Reputation: 4628
I've a .htaccess file and an index.html file in root directory of a domain. I've codes below in this .htaccess file:
DirectorySlash Off
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])?$ /index.html [L]
I hope users will see the contents in index.html when they access to a directory URL no matter this directory URL has trailing slash or not. So I have code above.
But I have a problem. When I access to a directory which doesn't exists. I get 404. This is not what I want. I hope users will always forever get 200 and see contents in index.html when they access to a directory URL. How can I resolve this problem by editing codes above in .htaccess file?
BTW. Please don't redirect users to the index.html file.
Thank you!
Upvotes: 1
Views: 2245
Reputation: 2952
Create a custom 404 page and call it for example "404page.php". Make sure that this page sends a 200 status before sending any other content to the browser by putting this at the top:
<?php
header("Status: 200 OK");
?>
Then enter ErrorDocument 404 /404page.php
in your htaccess.
Upvotes: 7