Forum Moderators: phranque

Message Too Old, No Replies

301 partial URL match

apache mod_rewrite partial match 301

         

elHelgo

9:29 pm on Jan 17, 2011 (gmt 0)

10+ Year Member



When I used to use blogger, it created static html files that Google still hits today. Something like the following:

sitename.com/blogarchive/2005_06_01_sitename_archive.html

A few years ago, I started coding everything up myself, but noticed that I need to 301 these. There are around 40-50 of them, so I don't want to go in one by one and do it. Does anyone know a way to do a mod_rewrite rule on just a partial part of the link above?

Here's the new part to where they should be going:

sitename.com/date/[year]/[month]/

I only care about stripping out the year and month and I don't care about anything after the "2005_06" in the example above.

Any help would be appreciated.

Thanks.

g1smd

9:46 pm on Jan 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, likely a one line RewriteRule with simple pattern matching to grab the year and month into backreferences to use in the substitution URL.

What code have you tried so far?

elHelgo

10:00 pm on Jan 17, 2011 (gmt 0)

10+ Year Member



I've tried this, but to no avail:

RewriteRule /blogarchive/([0-9]+)_([0-9]+)_$ sitename.com/date/$1/$2/ [R=301,L]

g1smd

10:11 pm on Jan 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Including the $ means the requested URL "must" end in an underscore.

The requested URL actually has more characters (which you want to ignore) after the underscore.

Simply remove the $ to let that happen.

Additionally, if this code goes in your .htaccess file, replace the leading / of the pattern with a ^ instead.

elHelgo

11:21 pm on Jan 17, 2011 (gmt 0)

10+ Year Member



Thanks, that did the trick.