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

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 serverfault.com), 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

1 Answer 1

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

 
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.