One*_*dio 9 .htaccess mod-rewrite redirect
使用htaccess,我需要将所有不包含特定URL路径(医疗保健)的URL重定向到新域,同时保持原始URL不变.
例:
healthcare.domain.com/anydirectory/anything.html
应该重定向到
staging.domain.com/anydirectory/anything.html
但任何包含/ healthcare的URL都不应被重定向.与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相同的根.然后我在医疗保健.domain.com的htaccess中设置重定向,以重定向到healthcare.domain.com/industries/healthcare,它完美无缺,但如果您点击/ industries/healthcare /之外的网站上的任何其他地方,我需要带用户回到staging.domain.com/whatever
这是我到目前为止:
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]
Run Code Online (Sandbox Code Playgroud)
Jon*_*Lin 11
尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^healthcare\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/healthcare/
RewriteRule ^(.*)$ http://staging.domain.com/$1 [L,R]
Run Code Online (Sandbox Code Playgroud)
您可以使用此代码:
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]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23231 次 |
| 最近记录: |