简体   繁体   中英

How to redirect multiple domains to another domain except 1 directory using htaccess?

I am trying to redirect multiple domains to a single domain (which is working fine) but i want one directory to not redirect or change the main domain url.

here is my .htaccess code it works fine until here

this one is working

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$ [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

but when i try to stop redirect of one specific directory by

full code

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$        [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

it all stops working :( with an error that page is not redirecting correctly.

extra code causing error

<pre>
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
</pre>

any help would be highly appreciated.

thank you!

Write your .htaccess like this:

RewriteCond %{HTTP_HOST} (www\.)?domain\.(org|net|com)$ [NC]
RewriteCond %{REQUEST_URI} !^/*no_redirect_dir/ [NC]
RewriteRule ^(.*)$ http://www.domain.info/$1 [R=301,L]

HTTP_HOST variable just has domain name, no http/https information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM