Reputation: 177
My htaccess 404 rule is set as follows:
ErrorDocument 404 /404.htm
but this is what happens:
Non-existent url with no extension: https://www.example.com/bgbgbgbgbg redirects to https://www.example.com/404.htm (correct behaviour)
non-existent url with a dot: https://www.example.com/bgbgbgbgbg. redirects to https://www.example.com/404.htm (correct behaviour)
non-existent url with extension: https://www.example.com/bgbgbgbgbg.htm redirects to "file not found" (should redirect to https://www.example.com/404.htm)
url endng with a slash: https://www.example.com/bgbgbgbgbg/ redirects to a weird 404 page with no css, and the urls in the browser's address bar does not change (should redirect to https://www.example.com/404.htm)
I did some research and tred implementing these lines right under ErrorDocument 404 /404.htm:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . https://www.example.com/404.htm [L]
it solves everything, BUT it redirects the homepage (https://www.example.com) to https://www.example.com/404.htm
What can I do in order to solve the homepage issue?
Upvotes: 0
Views: 58
Reputation: 41219
To redirect non existent requests to 404 error page you can simply use :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ /404.htm [L,R]
Upvotes: 1