使用htaccess,我需要将所有不包含特定URL路径(医疗保健)的URL重定向到新域,同时保持原始URL的完整性。
示例:
healthcare.domain.com/anydirectory/anything.html
应重定向到
staging.domain.com/anydirectory/anything.html
但是任何包含/healthcare的网址都不应该被重定向。就像在healthcare.domain.com/industries/healthcare/customers.html中一样,不应该重定向。
这两个域位于同一服务器上,并且healthcare.domain.com指向与staging.domain.com相同的根。他们希望能够在healthcare.domain.com上访问以下页面: staging.domain.com/industries/healthcare/。我将healthcare.domain.com设置为一个新的子域,将其根指向与staging.domain.com相同的根。然后,我在htaccess中为healthcare.domain.com设置了一个重定向,使其重定向到Healthare.domain.com/ redirect /healthcare,它工作得很好,但如果您在站点上单击/industries/healthcare/之外的任何其他位置,我需要将用户带回staging.domain.com/任何位置
这是我到目前为止所知道的:
RewriteCond %{HTTP_HOST} ^healthcare\.domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.healthcare\.domain\.com$
RewriteRule ^/?$ "http\:\/\/healthcare\.domain\.com\/industries\/healthcare\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^healthcare\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/healthcare/ [NC]
RewriteRule ^(.*)$ http://staging.domain.com/$1 [L,R=302]但是上面的代码总是返回http://staging.domain.com/index.php
发布于 2014-02-11 11:14:41
尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^healthcare\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/healthcare/
RewriteRule ^(.*)$ http://staging.domain.com/$1 [L,R]发布于 2014-02-14 01:31:33
您可以使用以下代码:
RewriteCond %{HTTP_HOST} ^(www\.)?healthcare\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/healthcare/ [NC]
RewriteRule ^(.*)$ http://staging.domain.com/$1 [L,R=302]
RewriteCond %{HTTP_HOST} ^(www\.)?healthcare\.domain\.com$ [NC]
RewriteRule ^/?$ http://healthcare.domain.com/industries/healthcare/ [R=302,L]https://stackoverflow.com/questions/21691986
复制相似问题