使用htaccss

时间:2015-05-18 18:59:21

标签: apache .htaccess redirect

我想要重定向链接:

http://www.domain.com/folder/file.php **to*      http://www.domain.com/file.php  

 http://www.domain.com/folder/folder/file.php **to*           http://www.domain.com/file.php  

到目前为止,我已尝试过这个

Redirect 301 /folder/file.php http://www.domain.com/file.php  
Redirect 301 /folder/folder/file.php http://www.domain.com/file.php  

这是有效的。我有100多个这样的文件来重定向,是否有一种简单的方法来减少我的代码,以便我可以用更少的代码来重定向更多。谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

您可以使用RedirectMatch指令:

将以下重定向放在root / .htaccess文件中的其他规则之上:

 RedirectMatch 301 ^/folder/folder/([^/]+)/?$ /$1 

 RedirectMatch 301 ^/folder/([^/]+)/?$ /$1 

答案 1 :(得分:0)

对于所有这些重定向,您只需在根.htaccess中使用一条规则:

RedirectMatch 301 /[^/]+/([^/]+)/?$ /$1
相关问题