将子网站重定向到另一个子网站URL

时间:2017-10-26 07:44:32

标签: apache .htaccess redirect

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

我想从子网站help.test.pl/site1重定向到此网站的另一个网址:help.test.pl/site1/info/sport

如果我在apache中做:

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

如果我在浏览器中运行网站help.test.pl/site1,那么" info/sport/" URL的循环。

网址如下:

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

我做错了什么?

1 个答案:

答案 0 :(得分: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]
相关问题