1

我有重复的网址,我需要在 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
4

1 回答 1

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]

于 2013-02-08T01:03:51.500 回答