.htaccess RewriteCond用于特定页面

时间:2023-02-03 11:11:08

I currently have a website on one domain and it has another domain mapped to it. I have a .htaccess RewriteCond like the following:

我目前在一个域上有一个网站,它有另一个域映射到它。我有一个.htaccess RewriteCond,如下所示:

RewriteCond %{HTTP_HOST} ^www\.additional-domain\.com [NC]
RewriteRule (.*) http://www.main-domain.com$1 [R=301,L]

This obviously means that any pages accessed by going to www.additional-domain.com will redirect to the correct page on www.main-domain.com.

这显然意味着访问www.additional-domain.com访问的任何页面都将重定向到www.main-domain.com上的正确页面。

What I would like to know is; can I keep this rule but have certain pages not redirect? so for page /this-page.html if the user accessed www.additional-domain.com/this-page.html then they are not redirected to www.main-domain.co.uk/this-page.html

我想知道的是;我可以保留此规则,但某些页面不能重定向吗?所以对于page /this-page.html,如果用户访问www.additional-domain.com/this-page.html,那么他们不会被重定向到www.main-domain.co.uk/this-page.html

Is this even possible? Thanks.

这有可能吗?谢谢。

-------- EDIT --------

--------编辑--------

I neglected to mention that for those additional pages I want the redirect to work in reverse.

我没有提到,对于那些额外的页面,我希望重定向反向工作。

So if someone accessed www.main-domain.co.uk/this-page.html then they would be redirected to www.additional-domain.co.uk/this-page.html

因此,如果有人访问www.main-domain.co.uk/this-page.html,那么他们将被重定向到www.additional-domain.co.uk/this-page.html

1 个解决方案

#1


5  

Add extra conditions to your redirect rule:

为重定向规则添加额外条件:

RewriteCond %{REQUEST_URI} !/this-page\.html
RewriteCond %{REQUEST_URI} !/this-page2\.html
RewriteCond %{HTTP_HOST} ^www\.additional-domain\.com [NC]
RewriteRule (.*) http://www.main-domain.com$1 [R=301,L]

#1


5  

Add extra conditions to your redirect rule:

为重定向规则添加额外条件:

RewriteCond %{REQUEST_URI} !/this-page\.html
RewriteCond %{REQUEST_URI} !/this-page2\.html
RewriteCond %{HTTP_HOST} ^www\.additional-domain\.com [NC]
RewriteRule (.*) http://www.main-domain.com$1 [R=301,L]