改变.htaccess改变中间

时间:2015-10-20 12:10:36

标签: apache .htaccess url-redirection

我已经改变了我的网站的结构,现在它更清洁,但谷歌在旧链接上显示用户404页面(我的学习曲线!)

我需要在我的.htaccess中写一些将用户转移到新路径的东西。

旧路径是www.example.net/designer-clothing/bags/hype-burgundy-backpack /

但是有数百个子类别,例如包包,衬衫,牛仔裤等。

我知道我可以使用:

Redirect 301 /designer-clothing/bags/ /product/

但是我必须列出每个子类别,是否有一些代码可用于将/designer-clothing/*/替换为/product/

或者,如果路径等于/designer-clothing/bags/hype-burgundy-backpack/,则接受网址的最后一部分(hype-burgundy-backpack)并将其附加到http://example.net/product/

2 个答案:

答案 0 :(得分:0)

简单如下:

RewriteEngine On
RewriteRule ^designer-clothing/[^/]+/(.+)$ /products/$1 [R=301,L,NC]

答案 1 :(得分:0)

作为上述接受答案的补充,您还可以使用 RedirectMatch 指令进行此重定向

RedirectMatch 301 ^/designer-clothing/[^/]+/(.+)/?$ http://example.com/products/$1