Reputation: 2628
I have a redesign of my site happening shortly where all the URLs are changing. Here's what I have put together so far http://cricketweb.net/new-design%20htaccess
Some research I've done has shown that this many lines within the .htaccess file is going to slow performance quite a lot.
I asked my hosting provider about it and they said:
"Your info is correct, adding this many redirects to your .htaccess will slow down the load time of your site pretty significantly. Adding these to the Apache conf unfortunately isn't a good idea on a cPanel server. cPanel makes edits to the conf file regularly and might not play nice with your edits. I'd recommend reevaluating the rewrite patterns first. For example, if domain1.com has folders a, b, and c and you want to send visitors to domain1.com/a to domain2.com/a, and the same for b and c, this could be accomplished with 1 rewrite rule. Unfortunately, if the URLs differ in inconsistent ways, like if you want to send visitors to domain1.com/a to domain2.com/asdf and visitors to domain1.com/b to domain2.com/zxcv, we may need to look into editing your apache preconf files with special rules for this domain, so please let me know if you will be able to shrink the number rules by consolidating them or not."
The problem being I don't see how I can consolidate these 301s.
Does anyone have any suggestions based off http://cricketweb.net/new-design%20htaccess
?
Upvotes: 3
Views: 1010
Reputation: 18671
It is not possible to optimize a relation of the type A -> B.
But when it is possible to find a repeating pattern,
A1 -> B, A2 -> B, A9999 -> B
or A1 -> B1, A2 -> B2, A9999 -> B9999
you can really reduce the number of lines.
Example: (More than 150 lines of the same type)
Redirect 301 \cricketgames\commercial\brianlaracricket05\demo100.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/
Redirect 301 \cricketgames\commercial\brianlaracricket05\demo101.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/
Redirect 301 \cricketgames\commercial\brianlaracricket05\demo102.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/
Can be simplified to: (1 line)
RewriteRule ^cricketgames/commercial/brianlaracricket\d+/demo\d+\.php$ http://www.cricketweb.net/game/brian-lara-international-cricket-2005/ [NC,R=301]
Other example (More than 160 lines):
Redirect 301 \cricketgames\commercial\internationalcricketcaptain2000\screenshot5.php http://www.cricketweb.net/game/international-cricket-captain-2000/
Redirect 301 \cricketgames\commercial\internationalcricketcaptain2006\screenshot13.php http://www.cricketweb.net/game/international-cricket-captain-2006/
Redirect 301 \cricketgames\commercial\internationalcricketcaptain2009\screenshot14.php http://www.cricketweb.net/game/international-cricket-captain-2009/
Can be simplified to: (1 line)
RewriteRule ^cricketgames/commercial/internationalcricketcaptain(20\d\d)/screenshot\d+\.php$ http://www.cricketweb.net/game/international-cricket-captain-$1/ [NC,R=301]
And there are so many cases of the same type in your file.
Then you also have the option to split your file into several parts (rewrites), to avoid testing all the lines eliminated from the beginning of the URL. This can for example divide by 20 to 30 the number of tests, just with an intermediate rewriting.
Upvotes: 5
Reputation: 8207
As a quick solution I propose to generate all these .php-file at the left side of rules, which will just redirect users to an URL at the right side.
As far as I can see, there is not way to to create new URLs from old URLs using regexps.
Upvotes: 0