如何使用htaccess重定向带有通配符的路径

Bry*_*ler 22 .htaccess mod-rewrite redirect

我有一个我最近升级的网站.旧网站有一个创建了数百个页面的日历,在新网站上已被事件页面替换,并且这些日历URL不再存在.几个月来,我一直在让搜索引擎不再像这些那样存在.

例如:

page not found calendar-for-groups/2012-09-15/1093
page not found calendar-for-groups/2011-W09/77
page not found calendar-for-groups/2011-W27/77
page not found calendar-for-groups/2012-06-29/1093
Run Code Online (Sandbox Code Playgroud)

如何使用htaccess将任何www.mywebsite.com/calendar-for-groups/*请求重定向到www.mywebsite.com/events

Flo*_*ern 42

您可以使用以下RedirectMatch指令mod_alias:

RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/events
Run Code Online (Sandbox Code Playgroud)

或者mod_rewrite:

RewriteRule ^calendar-for-groups/ http://www.mywebsite.com/events [R=301,L]
Run Code Online (Sandbox Code Playgroud)


小智 9

您可以使用一些重写规则:

RewriteEngine on
RewriteRule ^calendar-for-groups/(.*)   /events [R=301,L]
Run Code Online (Sandbox Code Playgroud)