Can anyone help out on the following?
old url
/market-barrow-green-p-543.html
new URL
/543-market-barrow-green.html
Assuming for the sake of discussion that you're going to do it in htaccess? There is definitely a difference between 40 rules and 30,000. (I am not making this up. Yesterday, I think, or the day before. Recent thread, anyway.)
The pattern I see is
(blahblah)-p-(\d+)
going to
$2-$1
BUT all those hyphens are troublesome. They won't break a RewriteRule, they just create a big potential for lost time and resources as mod_rewrite has to keep going back and forth until it captures exactly the right amount of text and no more. So the more narrowly you can constrain your pattern, the better. For example it would be ideal if you could say
^([a-z]+-[a-z]+-[a-z]+)-p-(\d+)\.html
on the Pattern side. Or -[a-z]- for the non-capturing bit if it can be any one letter.
Or do you mean 40
exact matches where each one has
{somespecifictext}
getting redirected to
http://www.example.com/{someotherspecifictext}
?
If so, you don't have to mess with finding rules and patterns. You just write out the exact text in its 40 variations.
Don't forget that everything passes through htaccess, not just pages. So ideally you'd want to intercept all requests for images, stylesheets etc and send them on their way without making them plow through all those rules. One of the many things htaccess can't do-- but any programming language can-- is a simple wrapper like
IF (request = \.html)
do stuff
END IF