Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently use the following htaccess code to remove php extensions and also allow the /index.php page to load without the word "index":

RewriteRule ^$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+[^/])$ $1.php [L]

I used to create a new page for every single user but as one could probably see, this is not such a good idea. So i deleted all the user pages and i would include them a different way but i would need to pass the requested page as a get parameter to another file. So I decided to route every main level (/) requested page through a file in a different directory, like so:

RewriteRule ^([^/]+)$ some/page.php?requested_page=$1 [L,QSA,NC]

But it does not work with the /index.php page if someone just requested it like this: /

i changed the code to:

RewriteRule ^(<?!)([^/]+)$ some/page.php?requested_page=$1 [L,QSA,NC]

and now the "/" request works and any page that really exist works, but the "fake user pages" now dont work. is there way i can do both?

share|improve this question
I have answered below, but I'm a bit confused by the regex in your fix attempt: ^(<?!)([^/]+)$ - I can't see how this would work at all, even for the / request? (<?!) looks like a parenthesised sub pattern that would match either <! or !? If you could explain that I would be very grateful. :) – w3dk Aug 11 '13 at 11:17
to be quite honest im not quite sure why it would work either. hahah. – Zach Aug 11 '13 at 13:32
up vote 0 down vote accepted
RewriteRule ^([^/]+)$ ....

This did not work for your index.php page when accessing as / since in that case the URL path is empty, but + matches 1 or more chars, so it doesn't match. Change + to * to match 0 or more.

share|improve this answer
thank you so much. – Zach Aug 11 '13 at 13:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.