Mobile app version of vmapp.org
Login or Join
Goswami781

: 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

@Goswami781

Posted in: #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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Goswami781

2 Comments

Sorted by latest first Latest Oldest Best

 

@Cody1181609

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.

10% popularity Vote Up Vote Down


 

@YK1175434

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]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme