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'm very, very (very!) new to using mod rewrite...I have the following set in my htaccess and it works as expected to remove the .php extension. My question is how to also make the url be extensionless if someone puts any extension on the end of the url? Right now etc all work, but so does I'd like to remove any extension on these pages!

Options +FollowSymlinks
RewriteEngine on
# remove php extension from all matching files
RewriteRule ^(share|invite|submission|thankyou|confirm|over|report)$ $1.php [NC]

I've tried several things and it always ends up breaking both functionalities. For some reason this stuff is the most impossible thing to find quick google answers for. Thanks in advance!

UPDATE: Working in a way, but getting infinite redirect loop:

Options +FollowSymlinks
RewriteEngine on
# reslove extensionless urls
RewriteRule ^(share|invite|submission|thankyou|confirm|over|report|emailtest)$ $1.php [NC]
# make .php redirect to extensionless urls
RewriteRule ^(share|invite|submission|thankyou|confirm|over|report).php$ /$1 [R=301,L,QSA]
share|improve this question
up vote 0 down vote accepted

Do you mean if someone types .../share.php, you want that to become .../share? If so, you need to redirect it.

RewriteRule ^(share|invite|submission|thankyou|confirm|over|report).php$ /$1 [R=302,L,QSA]

Change that 302 to 301 if it works, to make it do a permanent redirect.

share|improve this answer
Man, I was so close on that! This does work but throws me in an infinite redirect loop. I'm sure it's some flag that I don't know about that missing. I pasted the new code above. – Thomas McCabe Apr 14 '11 at 19:41
@Thomas McCabe: The problem with your updated code is order. You are rewriting the URL to end in .php, then saying, "if it ends in .php, redirect" - you need to change that [NC] for [L] and preferably put it after the other RewriteRule. [L] means last, as in this is the last rule that applies, stop rewriting here. – Orbling Apr 14 '11 at 21:12

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.