Eror 404 not working with directories

My code is not working for old pages that have trailing slashes which have been deleted

Actually the page is now site.com/page1 from site.com/page1/ if it has a trailing slash it gives a 500 internal server error/, not the 404 which happens on regular page that have no trailing slash.



ErrorDocument 404 http://www.domain.com/404

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

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



lukkas,

Some overlap with your other thread … but try using

ErrorDocument 404 /404.php 
# internal absolute URI is required

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^domain\\.com [NC] 
# escape the dot character and use No Case on domain names (which are NOT case sensitive)
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# (.*) duplicates the {REQUEST_URI} variable but if you [B]insist[/B] ...

RewriteBase / # ARGH! Forcing everything through the DocumentRoot when sitting in the DocumentRoot is not good technique.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\\.php -f # You forgot to escape the dot
RewriteRule .? %{REQUEST_URI}.php [L] # URIs are case sensitive so do NOT use No Case flag in a RewriteRule!

Explanations in the other thread.

Regards,

DK