【问题标题】:301 redirects of full addresses not folders301 重定向完整地址而不是文件夹
【发布时间】:2016-09-01 07:27:49
【问题描述】:

我的主要 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 实现这一目标?

【问题讨论】:

标签: .htaccess subdomain url-redirection


【解决方案1】:

如果您启用了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>

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

【讨论】:

  • 我写错了什么?它不工作:/ RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^pl.example.com$ [NC] RewriteRule ^/?(system_example/systems)/system_example_pp.html$ /$1/advantages.html [R=301,L ]
  • @Marcin 检查 mod-rewrite 是否处于活动状态。在 linux 系统上,你可以 sudo a2enmod rewrite
猜你喜欢
  • 2011-12-15
  • 2019-04-12
  • 1970-01-01
  • 2016-08-21
  • 2013-08-01
  • 2014-10-17
  • 1970-01-01
  • 1970-01-01
  • 2014-02-27
相关资源
最近更新 更多