我有重复的网址,我需要在htaccess中进行一些重定向
示例:
原始网址是:
www.mywebsite.com/listofgames/pacman.html
www.mywebsite.com/listofgames/nintendo.html
www.mywebsite.com/listofgames/snake.html
我有大约1000个游戏名称
重复网址示例:
www.mywebsite.com/listofgames/1/pacman.html
www.mywebsite.com/listofgames/1521/pacman.html
www.mywebsite.com/listofgames/52154/pacman.html
www.mywebsite.com/listofgames/abc/pacman.html
www.mywebsite.com/listofgames/opq/pacman.html
www.mywebsite.com/listofgames/opq/1/2/35/pacman.html
www.mywebsite.com/listofgames/154/3562/snake.html
www.mywebsite.com/listofgames/2541/snake.html
www.mywebsite.com/listofgames/524/snake.html
www.mywebsite.com/listofgames/absc/gtar/15/nintendo.html
www.mywebsite.com/listofgames/nije/nintendo.html
我需要将它们重定向到原始网址
所以
www.mywebsite.com/listofgames/anynumber/mygamesname.html
www.mywebsite.com/listofgames/anyword/mygamesname.html
www.mywebsite.com/listofgames/anyword/anynumber/anyword/mygamesname.html
必须重定向到
www.mywebsite.com/listofgames/mygamesname.html
答案 0 :(得分:1)
你可以试试这个:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/listofgames/.*/([^\.]+)\.html/? [NC]
RewriteRule .* listofgames/%1.html [R=301,L]
永久重定向
http://www.mywebsite.com/listofgames/any/number/of/folders/mygamesname.html
有或没有尾随斜杠。
要:
http://www.mywebsite.com/listofgames/mygamesname.html
有效删除/listofgames/
文件夹与HTML文件之间的细分路径。
listofgames
和扩展名html
是固定的,而假设mygamesname
是可变的。
必须保留传入的URL结构才能使规则集生效:URL中的最后一个字符串必须是HTML文件。
对于静音映射,请从R=301
[R=301,L]