开发者

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]
开发者_JAVA技巧    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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜