【问题标题】:Redirect subsite to another subsite URL将子网站重定向到另一个子网站 URL
【发布时间】:2017-10-26 07:44:32
【问题描述】:

我有(例如)网站 help.test.pl

我想从子站点 help.test.pl/site1 重定向到该站点的另一个 URL:help.test.pl/site1/info/sport

如果我在 apache 中这样做:

Redirect 301 /site1 https://help.test.pl/site1/info/sport

如果我在浏览器中运行站点 help.test.pl/site1,则 URL 的“info/sport/”会循环播放。

网址如下:

https://help.test.pl/site1/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport/info/sport

我做错了什么?

【问题讨论】:

标签: apache .htaccess redirect


【解决方案1】:

您可以使用下面的一种方法:

1) 使用RewriteRule

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} /site1$
RewriteRule ^/?(.*)$ https://help.test.pl/site1/info/sport [R=301,L]

2) 使用RedirectMatch

RedirectMatch 301 /site1$ https://help.test.pl/site1/info/sport

编辑:添加另一个页面。

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} /site1$ [OR]
RewriteCond %{REQUEST_URI} /site2$
RewriteRule ^/?(.*)$ https://help.test.pl/$1/info/sport [R=301,L]

【讨论】:

  • 第一个作品! Thx :) 我只有一个问题。我可以在 RewriteCond 中使用两个站点(参数)吗?例如 /site1$ 或 /site2$ ??
  • @Ebasse 是的,你可以,请查看我更新的答案。
猜你喜欢
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 2016-07-16
  • 2021-09-07
  • 2020-08-15
  • 1970-01-01
相关资源
最近更新 更多