wildcard 301重定向到忽略url中的变量

时间:2013-05-18 00:23:20

标签: apache .htaccess mod-rewrite

我没有为所有旧产品网址编写简单的重定向,而是需要重写规则来重定向几个链接,这些链接具有非常相似的网址,这些网址只有一个由句点分隔的数字不同。下面几个链接的示例将全部重写为单个URL。此外,在'a131.1.html'中也应忽略字符大小写,并且仅在文件名部分的目标网址中忽略。

site.com/product/cat/a131.1.html
site.com/product/cat/a131.2.html
site.com/product/cat/a131.3.html
site.com/product/cat/a131.4.html
...
site.com/product/cat/a131.30.html

to

new-site.com/101

2 个答案:

答案 0 :(得分:0)

类似的事情(因为我不清楚应该成为什么):

RewriteEngine On

RewriteRule ^product/cat/a([0-9]+)\.([0-9]+)\.html$ http://new-site.com/$1-$2 [L]

(我没试过,但希望它能奏效。在最坏的情况下,你现在知道要遵循的路线,你应该寻找什么)

答案 1 :(得分:0)

你可以缩小你的.htaccess。

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$
RewriteRule ^product/cat/a131\.\d+\.html$ http://newsite.com/b321 [R=301,L]
相关问题