For security reasons, I am making it so that all php files generate a 404 error, then using a custom 404 error page, like so:
RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/
RewriteRule ^.*$ - [R=404,L]
ErrorDocument 404 /error.html
Any php script I go to returns a custom 404 error page, as I would like, but below that it says:
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
But when I go to a page that actually doesn't exist (lets say http://localhost/Hello/world.html) I get the error page I want.
I'm confused, what am I doing wrong. Also, I would like to be able to use a php pagefor my custom ErrorDocument, but I'm not sure if that's possible.
You should try a redirect match:
RedirectMatch 404 ".*\.php"
This will pass the Not Found Error, and throw the appropriate ErrorDocument.
Related
I am trying to redirect the user to a page when 404 error occurred, so I am writing
ErrorDocument 404 /error.html
In .htaccess file and having an error.html file in my root directory but it's giving me
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Try resetting the error document to the system default prior to setting your custom document. For example:
ErrorDocument 404 default
ErrorDocument 404 /error.html
On some shared servers, the error document is (incorrectly) preconfigured in the main server config.
I want .htaccess to redirect to index.php on error, but with submitting some special GET variables.
For example, on error 404 I want it to redirect to
/index.php?article=404.php
I don't know how to do that as I haven't found any good tutorial for it.
This is what I tried:
RewriteEngine on
ErrorDocument 404 /index.php?article=404.php
ErrorDocument 403 /index.php?article=403.html
It seemed to work for 404 error, but for 403 error it shown:
Forbidden You don't have permission to access [...] on
this server. Additionally, a 404 Not Found error was
encountered while trying to use an ErrorDocument to handle the
request.
How should I do it?
I have a site (e.g. mysite.com) and old versions of the site under a directory are still appearing in search engines (e.g. mysite.com/oldsecton/something.html). There are too many of these links to remove from search engine finds.
I want everything in the /oldsection to redirect back to mysite.com/index.html
i.e. everything in the /oldsection should go to index.html located one directory path back
I have tried different variations of .htaccess inside /oldsection such as
ErrorDocument 404 ../index.html
ErrorDocument 404 mysite.com/index.html
etc...
None of them seem to be successfull.
This should be a simple task but I keep getting an Internal Server Error or a ErrorDocument error.
Inside /oldsection/.htaccess have this code:
RewriteEngine On
RewriteRule ^ /index.html [L,R=302]
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?
Try:
RewriteRule ^directory/ - [L,R=404]
This redirects all requests for the folder "/directory/", they get a 404 response.
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.
Redirect 404
Put this into the .htaccess file in the directory that you want off the record. The Redirect directive is part of mod_alias and can be used to send any status code, not just redirects.
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
I want to rewrite server errors (404, 500, etc) to url like this:
example.com/error.php?n=404
example.com/error.php?n=500
how to make it?
UPD:
Is there a universal way to handle all errors?
Try this :
ErrorDocument 404 /error.php?n=404
ErrorDocument 500 /error.php?n=500