Forum Moderators: phranque
I have a problem regarding htaccess and more specifically 301 L redirections..
I have a HUGE static web site which I now transform to dynamic and i dont want to loose my rankings :(
My first thought was to 'step' on the old urlz but after some analysis this proved to be impossible in some cases. So i will have to create hundreds of tiny rulz to redirect my old urls to the new ones! these rulz would look like:
######################################EXAMPLPE
RewriteRule ^crete/rethymno/hotels/rethymno-junior suite.htm$ [mywebsite...] suites-alpha.htm [R=301,L]
#####################################
I NEED MORE THAN 2000 RULZ to make it work...would it be possible to use a wildcard system?!
I hope i am clear enough to introduce you to my problem.
Hope the best and a HAPPY NEW YEAR
The usual approach is to leave the URLs alone, and simply do something like this:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^.]+)\.html$ /script.php?country=$1&city=$2/lodging=$3&provider=$4 [L]
You will probably need to add a few execptions to the above rule to allow your error pages to be static, since it's a good idea to keep error pages very simple and independent of any scripting support... In other words, keep your error pages static, so that they will still work even if your script fails.
Jim
I need to give you some more hints....
you mentioned "I can't tell exactly what you're doing, though, because your new URL appears to be static as well. "
This is because my new urlz have already been converted from php to htm (just a few lines before my 301 L redirections).....in plain words....
I first convert my php pages to htm
#########################################
RewriteRule ^(.*)/(.*)/hotels/(.*)-(.*)-category-(.*).htm$ list_category.php?area=$1&island_name=$2&island_name=$3&tname=$4&cat_name=$5 [nc]
########################################since the .htm created is not identical to my old page (static one_in most cases canot be done=EXCEPTION) I need another rule send all rankings to my new .htm......All these EXCEPTIONS are about 2000 so i need to use a wild card for the second phase of redirections.....
something like:
########################################
RewriteRule ^(.*)/(.*)/hotels/(.*)-(.*).htm$ [mysite...] [R=301,L]
########################################
One warning though: Avoid the use of multiple (.*) patterns in your rules. They are easy to write and easy to understand, but they are *horribly* inefficient -- subpattern processing time increases proportionally with the length of the 'tail' string (the remainder of the string following the current subpattern) and overall processing time increases geometrically with the number of (.*) subpatterns. See the example I posted above for a much better pattern. The regular-expressions tutorial cited in our froum charter may be helpful to decode it.
Jim
Notice that I used [^/]+ for all slash-delimited groups except the last, where I used [^.]+ because the delimiter for the filetype is "."
Jim