I am getting a 400 Bad request whenever i go to a product page - www.link.com/product/123/foo
RewriteRule ^product/([0-9]+)/(.+)/?$ product.php?product_id=$1&product_name=$2 [B,NC,L]
Related
The first few lines of my .htaccess file are as follows.
ErrorDocument 400 https://www.rydercragie.com
ErrorDocument 401 https://www.rydercragie.com
ErrorDocument 403 https://www.rydercragie.com
ErrorDocument 404 https://www.rydercragie.com
ErrorDocument 500 https://www.rydercragie.com
They all work apart from https://RyderCragie.com/.htaccess. Any ideas why an error is still shown on that page and how to fix it? Thanks.
Requests for .htaccess are quite likely blocked by directives in the server config - before the ErrorDocument in .htaccess is processed.
In order to catch this, you would need to define the ErrorDocument earlier in the main server config, not .htaccess. The same applies to other requests that are blocked early by Apache, such as requests that contain encoded slashes in the URL-path, and most 500 errors.
Although any request for .htaccess in the wild is unquestionably malicious, so a minimal (default) server response is probably the best response.
However, implementing all your ErrorDocument directives as external redirects to the document root is generally a bad idea (you lose details of the request that triggered the response, bad experience for users, etc.)
Give your user a meaningful error response, without the redirect. Error documents should be served via an internal subrequest. For example:
ErrorDocument 403 /error-documents/e403.html
Reference:
https://httpd.apache.org/docs/2.4/mod/core.html#errordocument
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 want to REDIRECT 404 error page to custom 404 page. For example, if http://example.com/abc.html causes 404 error, I want redirect the page to http://example.com/404.html with 404 http response code. It is possible?
So far there is NO OPTION to redirect 404 error page to a custom 404 page with 404 http response code. To get 404 http response code, you will need to display custom 404 error page content without redirection like following code:
ErrorDocument 404 /404.html
And if you use following code, the 404 error page will be redirected to the custom 404 page with 302 http response code
ErrorDocument 404 http://www.yourdomain.com/404.html
Since you are using Apache, you can use the ErrorDocument directive (docs).
You are encouraged to use an internal rewrite for this, so the client receives the correct statuscode for the request (404). If you make it redirect to this page, the client will receive a 301 or 302 header instead for the non-existing page, which can confuse automated webservices, such as webcrawlers.
To make it internally rewrite:
ErrorDocument 404 /404.html
To make it externally redirect
ErrorDocument 404 http://yoursite.com/404.html
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
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.