301重定向的完整地址不是文件夹

时间:2016-09-01 07:27:49

标签: .htaccess subdomain url-redirection

我的主要example.com中有很多子域名,例如us.example.com,gb.example.com,fr.example.com,pl.example.com等。

现在我需要从不存在的站点到新站点执行301重定向。通常我会以最简单的方式完成它:

Redirect 301 /system_example/systems/system_abc.html http://pl.example.com/system_example/systems/all_systems.html

但是这在我所拥有的网站结构中是不可能的,因为具有该路径的所有其他子域/system_example/systems/system_abc.html现在将重定向到http://pl.example.com/system_example/systems/all_systems.html

我只想在pl.example.com子域中进行重定向 - 所有其他的都需要保持不变。如果只有这种类型的重定向有效,但它没有:

Redirect 301 http://pl.example.com/system_example/systems/system_abc.html http://pl.example.com/system_example/systems/all_systems.html

是否可以通过.htaccess实现这一目标?

1 个答案:

答案 0 :(得分:0)

如果您启用了mod-rewrite,那么:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^pl\.example\.com$ [NC]
RewriteRule ^/?(system_example/systems)/system_abc\.html$ /$1/all_systems.html [R=301,L]

否则,仅使用mod-alias

<If "%{HTTP_HOST}" == "pl.example.com">
    RedirectPermanent /system_example/systems/system_abc.html /system_example/systems/all_systems.html
</If>

我不确定第二个是否在语法上是正确的。