I need to have a RegEx that will match a URI like this based on the subdomain “blog”–
http://blog.foo.com/2010/06/25/city-tax-sale/
and redirect like this (getting rid of the subdomain and numbers/date)–
where the last bit “city-tax-sale” would be a wildcard. So basically any incoming URI that starts with ‘blog.foo.com’ would be redirected to ‘foo.com’ + ‘whatever is at the end of the above URI after the three sub paths with numbers.
I hope that makes sense. Just trying to create one redirect instead of writing every single one.
This will explicitly match your date format, rather than any series of digits and slashes:
The regex part can be broken does to:
With the
$1in the replacement being group 1.In the options part:
Lis for “Last” – tells it to not bother looking at other rules.R=301is for Redirect with 301 header, which means permanent redirect (just R would send a temporary 302 header)The RewriteCond bit performs a case-insensitive (NC option) check on the
HTTP_HOSTheader (supplied by user/client) and if it startsblog.foo.comit performs the rewrite, otherwise it doesn’t.