Question

I think the title is clear; I want to create a rule on web-server that if a user tries to reach specific path like http://mysite.com/admin face the 404 error, while this folder is available and contains files. If my cookie is set on the client's system, he/she can visit that path.

I'm looking for a .htaccess solution, but any other answers (php or anything) are appreciated too.

I'm not familiar with writing rewrite rules but this may help:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/admin
RewriteCond %{HTTP_COOKIE} !myCookie=9856012345
RewriteRule .* - [L,F]

It shows 403 error, and people will know that the path exists, I want them to feel there's no such path on the folder by showing 404 error.

Was it helpful?

Solution

You can do it by using a 404 redirect

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/admin
RewriteCond %{HTTP_COOKIE} !myCookie=9856012345
RewriteRule .* - [L,R=404]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top