I want URLs with a specific path to return an automatic 200 status response. I have tried the below, but get a an error when I try to start Apache:
First error: RewriteCond: bad flag delimiters
RewriteEngine On
RewriteCond %{THE_REQUEST} GET /the_url/
RewriteRule ^ - [R=200]
If I remove the path part then I do not get the error:
RewriteEngine On
RewriteCond %{THE_REQUEST} GET
RewriteRule ^ - [R=200]
But, of course, I need a way to include the path requirement.
Another error is that, even when the server does return a status 200 above (verified in Developer Tools), then the page still displays an error message: "OK The server encountered an internal error or misconfiguration and was unable to complete your request...." Is it not really returning a status 200? Or is it, but this is just what the default HTML page is when nothing is provided by the server?
F|forbidden The following rule will forbid .exe files from being downloaded from your server. RewriteRule "\.exe" "-" [F] This example uses the "-" syntax for the rewrite target, which means that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.
In your rewrite, the ^ signifies the start of the string, the (. *) says to match anything, and the $ signifies the end of the string. So, basically, it's saying grab everything from the start to the end of the string and assign that value to $1.
A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
The following did the trick. From https://httpd.apache.org/docs/2.4/custom-error.html
Enable the mod_rewrite module
LoadModule rewrite_module modules/mod_rewrite.so
and then add the following to your virtual host.
ErrorDocument 200 "ok"
RewriteEngine On
RewriteRule "/the_url/" - [R=200]
EDIT:
My original answer has been edited so much by someone else that it is no longer quite the same. I'll leave the edited answer (above), but I did not have to enable the mod_rewrite module. Some Linux distributions come with this by default or your host might have provided it as their default starting point. I added the three lines to httpd.conf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With