Reputation: 825
I have a .htaccess file that essentially "removes" the file extension in the web browser (from example.php to example). Here's the code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Basically, if the file (about) isn't found, it adds the .php extension (about.php). I want to (if the file still isn't found) redirect the user to 404.php. So if the user loads /page1, and page1.php doesn't exist, it redirects to the 404 page. I added this code to the .htaccess:
ErrorDocument 404 /404.php
On it's own, this code will redirect to the 404 page. But when I have the entire code...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
ErrorDocument 404 /CWTC/404.php
...it just shows a "500 Internal Server Error".
Does anyone know what I'm doing wrong?
Thanks!
Upvotes: 0
Views: 3401
Reputation: 825
This has solved my problem:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
ErrorDocument 404 /404.php
Thanks!
Upvotes: 2