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 not experienced in editing .htaccess

I wanted to

  1. redirect non-www to www.

  2. remove .php extension

  3. set up a custom 404 page

I managed to do this (looking for solution in the web and on, but now it seems that my old redirect 301 with .php extension are not working anymore:

redirect 301 /download.php /features.php

how I could solve it? Thank you!

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]

Options +FollowSymlinks
ErrorDocument 404 /404
RewriteEngine on 
share|improve this question

You need to add the PT flag to your RewriteRule:

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [PT]

The reason is that the substitution in a RewriteRule is normally assumed to be a file path, not a uri, and thus directives like Redirect etc. are not applied. The PTflag (pass through) tells apache to consider the rewrite rules as an uri, and keep applying uri mapping rules.

share|improve this answer

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.