Mod_rewrite stops missing.html from working



I have used the following code from the dreamhost wiki to my .htaccess file to clean up my URLs by not displaying the .php extensions in the URLs.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /$1.php [L,QSA]

This works fine, I don’t need to php extensions, it works as it should. My custom 404 page doesn’t work though. I am getting a 500 Internal Server error:

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."

The only text in my .htaccess file, is the text I posted above.

I have tried a few different things, none of which worked, such as adding:

ErrorDocument 404 /missing.html

I really hope someone can help me, it is driving me crazy!


you told it that if the request isn’t for an existing file or directory, add .php to the end and try again. you’ll never get to your error document that way and it will just keep adding .php to the end and trying again. you should add another condition to ensure the .php file exists:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(. )$ /$1.php [L,QSA]
ErrorDocument 404 /missing.html

can you post the URL to where you found that on the dreamhost wiki? i’ll go make sure it’s correct.

track7 - my dream-hosted site


Thanks for your reply. The code came from this page under the heading “No File Extension”:

I tried the code that you posted, and am getting the same internal server error message.


it turned my plus sign on the RewriteRule line into a space – that line should have been the same as your first line. what url are you trying to access, and what’s the php file? do you have anything else in you .htaccess file?

track7 - my dream-hosted site


Aha! I added the plus and it works fine now! All of my php pages display without the extension, and if I deliberately type a page name which doesn’t exist, I get my custom 404 page.

Thanks very much for your help, I appreciate it very much! :slight_smile: