Redirect whole domain except 1 directory

Hi all,

I am trying to redirect a whole domain except 1 directory - this is the code i have:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_URI} !/.well-known/
RewriteRule (.*)$1 [R=301,L]

I am making sure that always we use WWW and HTTPS
Then checking the directory not to redirect and then everything else to redirect.

Anyone got any ideas ?


Hi Rudi,

1. Maybe you need to move RewriteCond %{REQUEST_URI} !/.well-known/ section to the top?
2. How about combine HTTPS and WWW to something like
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.
Thanks for the suggestion, I combined the HTTPS and WWW that worked nice, but moving RewriteCond %{REQUEST_URI} !/.well-known/ up didn't work. I also tried RewriteCond %{REQUEST_URI} ^!/.well-known/ as well.


RewriteCond %{REQUEST_URI} !/testdirectory
RewriteRule ...

it should work. otherwise, you can turn on rewrite debug log to see where it failed. or log a ticket with tmp root ssh login, we can check for you.


by the way, for openlitespeed, every time you make changes to .htaccess, you will need to restart openlitespeed to make changes to .htaccess effective.