我想将多个重定向旧网站网址添加到新网址
当前我有这个网址格式
http://example.com/product/cat1/cat2/61600
我要使用以下模式将所有具有上述模式的页面重定向
http://example2.com/canbenaything-61600.html
但是,根据这种情况,我想重定向“上一个网址”部分上的所有网址为61600。
答案 0 :(得分:1)
对于您的特殊情况,请将其添加到您的.htaccess
文件中
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^product/cat1/cat2/(.*)$ "http\:\/\/example2\.com\/canbenaything-$1.html" [R=301,L]
以下行将匹配example.com,这是重写条件
RewriteCond %{HTTP_HOST} ^example\.com$
以下行将匹配product/cat1/cat2/(.*)
之后的查询字符串,并存储其中的内容代替(.*)
RewriteRule ^product/cat1/cat2/(.*)$
整行将重定向到新URL
RewriteRule ^product/cat1/cat2/(.*)$ "http\:\/\/example2\.com\/canbenaything-$1.html" [R=301,L]
如果您要将http://example.com/anything/some_id重定向到http://example2.com/something_else-some_id.html
然后下面的行将起作用
RewriteRule ^(.*)/(.*)$ "http\:\/\/example2\.com\/something_else-$2.html" [R=301,L]