: How to use .htaccess with exclusions I want all requests on a domain to be redirected to https, with the exception of just one particular file. I'm not sure how to accomplish this with .htaccess
I want all requests on a domain to be redirected to https, with the exception of just one particular file. I'm not sure how to accomplish this with .htaccess
-bash-3.2# cat .htaccess
ErrorDocument 404 www.example.com RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ www.example.com/ [R,L]
-bash-3.2#
The above code redirects everything perfectly, however, I need the robots.txt file to be accessible via vs the only.
More posts by @Goswami781
2 Comments
Sorted by latest first Latest Oldest Best
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !robots.txt
RewriteRule .* www.example.com/[CO] [R,L]
Note that HTTPS is a more reliable indicator of whether or not SSL is enabled.
This would fit better in serverfault but...
You can work with a pre-condition first. Something like:
ErrorDocument 404 domain.com
RewriteEngine On
RewriteCond %{REQUEST_URI} (www)?.domain.tld/robots.txt RewriteRule domain.tld/robots.txt [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ domain.com/ [R,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.