mod_rewrite and query string

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
LVL 8
us111Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

caterham_wwwCommented:
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]
rama_krishna580Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
us111Author Commented:
>>>it is now classified as abandoned
No, sorry but leave this question opened for the moment


The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

periwinkleCommented:
Is there still a problem that we can assist you with?  What happened when you followed the advice given by the experts above?
us111Author Commented:
No no I think it's ok. But I need to test...
us111Author Commented:
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
us111Author Commented:
I'm agree with your arguments

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

Points splited
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.