0

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 
mattewre
  • 31
  • 4

1 Answers1

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.

Krist van Besien
  • 1,832
  • 13
  • 16