?
Solved

mod_rewrite and query string

Posted on 2006-03-29
11
Medium Priority
?
372 Views
Last Modified: 2010-03-04
http://www.domain.com/gallery/mygallery/index.html

should be rewrited into

http://www.domain.com.com/index.php?gallery=mygallery but the url I have to see in my browser is http://www.domain.com/gallery/mygallery/index.html


and the same for :

http://www.domain.com/gallery/mygallery/1/index.html 

should be rewrited into

http://www.domain.com/index.php?gallery=mygallery&img=1
0
Comment
Question by:us111
7 Comments
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 1000 total points
ID: 16326800
So you're planning to use the RewriteRules in a .htacccess file? Or in httpd.conf?

That would be for a .htaccess file:

RewriteEngine on
RewriteRule ^gallery/([^/]+)/index\.html$ /index.php?gallery=$1 [L]
RewriteRule ^gallery/([^/]+)/([0-9]+)/index\.html$ /index.php?gallery=$1&img=$2 [L]

for httpd.conf, just add a leading slash in the pattern:

RewriteEngine on
RewriteRule ^/gallery/([^/]+)/index\.html$ /index.php?gallery=$1 [L]
RewriteRule ^/gallery/([^/]+)/([0-9]+)/index\.html$ /index.php?gallery=$1&img=$2 [L]
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 1000 total points
ID: 16344316
Hi,

More Advanced - the Query String:

The query string is passed in separately from the URL. This means that a simple regex doesn't necessarily do the trick, but a compound statement using RewriteCond (condition) is required.

RewriteCond %{QUERY_STRING} id=([^&;]*)
RewriteRule ^/$ http://%{SERVER_NAME}/%1/? [R]
RewriteRule ^/([^/]*)/?$ /index.php?id=$1 [L]

The RewriteCondition matches only when the following condition is true, and continues until a "last" [L] is stated. The Condition's backreferences are different, using the % prefix, and their scope lasts beyond the Condition line.

This above example would translate "/?id=home" into "/home/", and then re-assign the value of "home" to the id HTTP_GET_VAR. One more thing to notice here is that the the second line has a trailing ? - this is used to negate copying of the query string into the new, re-directed URI.

More Reference Links:

http://www.engelschall.com/pw/apache/rewriteguide/
http://httpd.apache.org/docs/mod/mod_rewrite.html
http://httpd.apache.org/docs/misc/rewriteguide.html

R.K
0
 
LVL 8

Author Comment

by:us111
ID: 16523047
>>>it is now classified as abandoned
No, sorry but leave this question opened for the moment


0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 15

Expert Comment

by:periwinkle
ID: 16576387
Is there still a problem that we can assist you with?  What happened when you followed the advice given by the experts above?
0
 
LVL 8

Author Comment

by:us111
ID: 16583585
No no I think it's ok. But I need to test...
0
 
LVL 8

Author Comment

by:us111
ID: 16782832
Please leave it opened.

I know you have to clean but this question has only 3 month. I think it's better to clean questions from 2005!

I'm gonna do my best to close it.  btw i will increase the points
0
 
LVL 8

Author Comment

by:us111
ID: 16840466
I'm agree with your arguments

Anyway, as I have no time to test I suppose it works......

Points splited
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question