Send a 404 error via htaccess?

徘徊边缘 提交于 2019-12-21 03:13:12

问题


I'd like to cut off access to a subdirectory on my site but I want any access in the subdirectory to be a 404 error, not a 403 forbidden. How can this be accomplished?


回答1:


Try:

RewriteRule ^directory/ - [L,R=404]

This redirects all requests for the folder "/directory/", they get a 404 response.




回答2:


You could also for the time being change which page a user will see when confronted with a 403 error, but I wouldn't recommend doing this long-term.

.htaccess:

ErrorDocument 403 /your404pagehere.php



回答3:


I think, 410 error better

RewriteRule ^directory/ - [L,R=410]

or my search:

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|Baiduspider) [NC]
RewriteRule .* - [R=410,L]

on russian wiki

404 Not Found [19] - the most common mistake when using the Internet, the main reason - an error in writing the address of a Web page. The server understood the request, but did not find the corresponding resource at the specified URL. If the server knows that there was a document at this address, then it is desirable for it to use code 410. Answer 404 can be used instead of 403 if you need to carefully hide certain resources from prying eyes. Appeared in HTTP/1.0.



来源:https://stackoverflow.com/questions/18730683/send-a-404-error-via-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!