Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use htaccess to redirect paths with a wildcard character

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.

For example:

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

How can I use htaccess to redirect any www.mywebsite.com/calendar-for-groups/* request to www.mywebsite.com/events?

like image 401
Bryan Casler Avatar asked Jul 29 '11 18:07

Bryan Casler


People also ask

What is a wildcard URL?

Wildcard URLs provide a way to load content dynamically depending on the page URL. By using wildcards, you can pass the values of query string parameters directly as part of the URL path.

How can I redirect and rewrite my URLs with an .htaccess file?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.


2 Answers

You could use the RedirectMatch directive of mod_alias:

RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/events

Or with mod_rewrite:

RewriteRule ^calendar-for-groups/ http://www.mywebsite.com/events [R=301,L]
like image 181
Floern Avatar answered Oct 20 '22 03:10

Floern


You can do with a few rewrite rules:

RewriteEngine on
RewriteRule ^calendar-for-groups/(.*)   /events [R=301,L]
like image 36
Marco Bizzarri Avatar answered Oct 20 '22 01:10

Marco Bizzarri