如何使用 htaccess 重定向带有通配符的路径 [英] How can I use htaccess to redirect paths with a wildcard character
问题描述
我最近升级了一个网站.旧站点的日历创建了数百个页面,在新站点上,它已被事件页面取代,并且这些日历 URL 不再存在.几个月来,我一直让搜索引擎猛烈抨击这些不再存在的页面.
I have a site I recently upgraded. The old site had a calendar that created hundreds of pages, on the new site this has been replaced by an events page and those calendar URL's no longer exist. For months now I have been getting search engines pounding no longer existent pages like these ones.
例如:
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
如何使用 htaccess 将任何 www.mywebsite.com/calendar-for-groups/*
请求重定向到 www.mywebsite.com/events
?>
How can I use htaccess to redirect any www.mywebsite.com/calendar-for-groups/*
request to www.mywebsite.com/events
?
推荐答案
您可以使用 mod_alias
的 RedirectMatch
指令:
You could use the RedirectMatch
directive of mod_alias
:
RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/events
或者使用mod_rewrite
:
RewriteRule ^calendar-for-groups/ http://www.mywebsite.com/events [R=301,L]
这篇关于如何使用 htaccess 重定向带有通配符的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!