为什么htaccess RewriteRule不会“粘”?

时间:2019-03-17 13:54:34

标签: .htaccess redirect

我正在尝试将http://vacation.website.com/category/spa-vacations/重定向到http://website.com/vacations/spa-vacations/

RewriteEngine On
RewriteRule ^category/(.*)$ $1
RewriteCond %{HTTP_HOST} ^vacation\.website\.com [NC]
RewriteRule ^(.*) https://website.com/vacations/$1 [L,R=301]

Screencap from htaccess tester

使用此htaccess,似乎应用了第一个规则,并从URL中删除了“类别”-就像从未发生过,我留下了http://website.com/vacations/category/spa-vacations/

为什么不对URL进行第一次更改,是否有可能这样做?

1 个答案:

答案 0 :(得分:1)

要重定向

http://vacation.website.com/category/spa-vacations/

http://website.com/vacations/spa-vacations/

尝试一下:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?vacation\.website\.com [NC]
RewriteRule ^category/(.*)$ https://website.com/vacations/$1 [L,R=301]

注意:清除浏览器缓存,然后进行测试。