mod rewrite - mod_rewrite with question marks and ampersands (with PHP) -


I have a PHP based web app that I am trying to implement mod_rewrite of Apache.

The original URL is of the form:

And I want to convert it to:

Note that the page name is rewritten Time, I am also effectively question question "walk" When I try to do this, Apache happily executes this translation:

  Rev. Rule ^ / ([az ] +) \? (. +) $ /index.php?page=$1&$2 [NC, L]  

but it corrupts the $ _ GET variable in PHP For example, call on http://example.com/home?x=88 only a $ _ GET variable ( page => home ). x = & gt; 88 Go? However, when I change my rule to use an ampersand instead of a question mark:

  RewriteRule ^ / ([az] +) & amp; (. +) $ /index.php?page= $ 1 and $ 2 [nc, l]  

A call such as http://example.com/home&x = 88 will work as I want it to expect (i.e. both page and x $ _GET variables are set properly).

At least I know the difference, but I want to have a url variables with a question mark to "start", if this is possible, I am sure that this is my own misunderstanding Indicates how mod_rewrite redirects interacts with PHP, but it seems that I should be able to do this (one way or another).

Thanks in advance! , - -Chris

Try it out :.

  Rewrite% {REQUEST_URI}! ^ / Index.php rewriterele ^ / ([?]] + (?: $ | \? (?:. +)) /index.php?page=$1 [nc, l, b, qua, northeast]  

B is avoided by backbreaking (it should not be necessary because it matches [az] +, but if you want to increase it later, it can be useful).

Edit: Added RewriteCond 2 Edit: AMS takes care of adding ampersand.


Comments