View Full Version : Rewrite not picking up variable

11-14-2010, 09:17 PM
Hi I have the following re_write condition:

RewriteRule ^([^/\.]+)\.php$ index.php?page=$1 [L]

Which when I try to access the page like www.domain.com/newsite/hello.php
the only thing stored in the $_GET is "index".

Can someone explain to me what I have managed to do wrong? I know it is slightly working because when I change it to:

RewriteRule ^([^/\.]+)\.php$ index.php?page=bob [L]

it supplies the $_GET with the string "bob".


11-16-2010, 09:14 PM
At at guess, when it iterates the second time round you'll match the index.php in the redirect.

Untested - but try this:

RewriteRule ([^/\.]+)([^index])\.php$ index.php?page=$1 [L]

11-16-2010, 09:44 PM
Thanks for the reply. It did not work instantly but I have managed to work it.


RewriteRule ^([^index])([^/\.]+)\.php$ index.php?page=$1$2 [L]

This code works if anyone else requires it. I dont understand why it works though. If anyone can explain it that would be aces.

Note: the $1$2 at the end is required as only part of the variable is put in each.