0

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?

0

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.

3
  • This doesn't appear to do what I want. Doesn't this change foo.php?bar into bar.php? – Leagsaidh 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. – Leagsaidh Gordon Dec 4 '12 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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