Removing file extensions


Removing file extensions

Postby shires82 » Thu Mar 24, 2011 8:59 am

Just taken on a site that has a rewrite rule in place to remove & redirect .php extensions. i.e /about.php will become /about.
However, there are other rules in place and I have just noticed that if the url parameter doesn't match the rewrite condition a 501 Internal Server Error is thrown as opposed to a 404.
It is definately the rule that removes the .php that is causing the issue as commenting it out solves the issue, however this rule must be left in place.

Code: Select all
RewriteEngine On
RewriteBase /

RewriteRule ^archive/([A-Z]{1})$ archive.php?letter=$1 [L]
RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]

# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

ErrorDocument 404 /missing
ErrorDocument 403

Ok, so if the URL is then it works fine. Same for removing the .php extension will become However if I try to use an invalid URL (on an existing mod rewrite rule) to test a 404 i.e then I will get a 500 Internal server error.

Any ideas? Mod Rewrite not really my strongest area for debugging.
Posts: 3
Joined: Wed Jun 13, 2007 3:46 am

Return to New Threads/Problems

Who is online

Users browsing this forum: No registered users and 2 guests