lucy24 - 1:54 am on May 1, 2012 (gmt 0)
I have over 300 5-10 year old 301 redirects like this and there is no way I can simplify them. So should I also use RewriteRule for them and move them up?
5-10 years old?!?!?! Just how slow on the uptake are your users? If you're waiting for search engines to stop periodically crawling old URLs ... well, I hope you come from a long line of centenarians.
My current rough-and-ready rule, just because I had to come up with something, is:
Redirect (301) for one year (rounded off to the nearest quarter to make it easier for me to keep track).
Change to Gone (410) for another year. If you don't already have a custom 410 page for humans, make one. Or simply send 'em to your 404 page. At the beginning of this period there will be a flurry of activity as the search robots run around screaming Where'd it go? What happened? Something has changed! but it will soon level off.
After the second year, pull the plug. Yank those long-gone suckers out of your htaccess entirely. Again, make sure you have a nice human-friendly 404 page and keep its links up-to-date. The search engines will still come by periodically to sulk. But at this point they are just being silly and can be safely ignored.
That's for pages. For supporting files, three months instead of a year.
If you have a text editor that speaks RegEx (just about any dialect will do), open a copy of your htaccess. If you are brave, this should even work as an unsupervised global replace.
#1 change . to \.
^(Redirect \d\d\d \S+?[^\\])\. TO $1\\.
#2a now change Redirect to Rewrite
^Redirect(?:Match)? 301 /(.+) TO RewriteRule $1 [R=301,L]
^Redirect(?:Match)? 410 /(.+) TO RewriteRule $1 - [G]
For sorting: In general, sort in order of strongest to weakest: [F] before [G] before [R] before your basic Rewrite in [L]. (I stress: in general. There are exceptions.) Within each group, sort from most specific to most general. If a Rule has more than one Condition, start with the one most likely to fail.
If you have a whole bunch of conditionless Rules, like all those former Redirects, you may group them thematically without putting a space after every single one. But always space before and after a Condition(s)-plus-Rule group.