小编One*_*dio的帖子

如果url不包含特定目录,则htaccess重定向

使用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)

但以上总是返回http://staging.domain.com/index.php

.htaccess mod-rewrite redirect

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

.htaccess ×1

mod-rewrite ×1

redirect ×1