Server Fault is a question and answer site for system and network administrators. 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 want specific pages without an extension to direct to their php counterpart. Right now, I have this:

RewriteEngine on
RewriteRule ^(login|logout)$ $1.php
RewriteRule ^(login|logout)\?(.*)$ $1.php?$2

Is there a way to do this in one rule? Should I do this in one rule?

share|improve this question

This will generalize it for just about any possible filename. Tweak the pattern match if you need to. (Thank you to the Internet for this example.)

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?([a-zA-Z0-9]+)$ $1.php [L]

Or you can enable Options +MultiViews but this may carry a performance penalty, since while it works it's not what MultiViews was designed for.

share|improve this answer
This doesn't appear to do what I want. Doesn't this change foo.php?bar into bar.php? – Sean Gordon Dec 4 '12 at 18:57
No, it changes /foo?bar into /foo.php?bar if /foo.php is a file that exists on the filesystem. – Michael Hampton Dec 4 '12 at 19:02
My bad, the initial / threw me. I still don't understand this though. – Sean Gordon Dec 4 '12 at 20:17

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.