Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.