Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a 404 error via htaccess?

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?

like image 235
Citizen Avatar asked Sep 11 '13 00:09

Citizen


People also ask

How do I trigger a 404 error?

One typical trigger for an error 404 message is when the page has been deleted from the website. The page was moved to another URL and the redirection was done incorrectly. You entered an incorrect URL address. Although it happens very rarely, sometimes the server malfunctions.

How do I redirect 404 error to custom error page?

To have a custom 404 page for this error, we should edit our . htacess file, which is located under the root folder (usually inside the public_html folder for cPanel servers). If you can't find the . htacess file, you can simply create it.


2 Answers

Try:

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

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

like image 51
Jon Lin Avatar answered Sep 22 '22 12:09

Jon Lin


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.

like image 40
MrSwed Avatar answered Sep 25 '22 12:09

MrSwed