htaccess结合了特定和一般重定向问题

时间:2013-11-12 20:19:49

标签: regex apache .htaccess mod-rewrite

将域名从ExampleShop.com更改为ExampleStore.com

我在尝试重定向约30个特定页面时遇到问题,并且还对URL映射未仅更改域的页面执行通用重定向。

这就是我所拥有的,它使用通用重写规则重定向所有内容,而不是重定向特定的重写。

Options +FollowSymLinks
RewriteEngine on

#Specialty Rewrites for non-exact mapped URLs
RewriteRule ^/gifts/jewellery/bracelets.html$ http://www.ExampleStore.com/gifts/jewellery/bracelets.html [R=301,L]

RewriteRule ^/gifts/watches/banded.html$ http://www.ExampleStore.com/gifts-for-him/jewellery/watches.html [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Generic Rewrite for exact mapped URLs
RewriteRule ^(.*)$ http://www.ExampleStore.com/$1 [R=301]

1 个答案:

答案 0 :(得分:1)

删除前导斜杠:

RewriteRule ^gifts/jewellery/bracelets.html$ http://www.ExampleStore.com/gifts/jewellery/bracelets.html [R=301,L]

RewriteRule ^gifts/watches/banded.html$ http://www.ExampleStore.com/gifts-for-him/jewellery/watches.html [R=301,L]

.htaccess是每个目录指令,Apache在RewriteRule中使用时会从URI中删除前导斜杠。