Adding 301 redirect for more than 1000 pages

Discussion in 'robots.txt' started by greatlogix, Oct 3, 2007.

  1. #1
    I have changed URLs of my site using mod rewrite. My site has more than 1000 pages. Now is it a good idea to add 1000 301 redirects to robots.txt? or I should add it to .htacces file. In both cases I will have 1000 lines for redirect. Will it effect site performance. Please suggest what is better approach for adding redirects.
     
    greatlogix, Oct 3, 2007 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    301 redirects are done using RewriteRules and they don't go in robots.txt. They can be done in either a .htaccess file or in the vhosts file.

    RewriteRules use regular expressions to match the request string and then specify another string to replace it along with some options about what it should do when the string matches the rule. You can also use part of the original request string in the replacement string. For example:

    RewriteRule (.*)\.jpg images/$1.jpg [R=301,L]
    Code (markup):
    Would cause any browser requesting /anything.jpg to be told that that image had moved permanently to /images/anything.jpg

    This code, on the other hand:

    RewriteRule (.*)\.jpg images/$1.jpg [L]
    Code (markup):
    Would simply send them back the jpg file, even though it was now stored in /images.

    If you have changed all of your images to end in .jpeg or .JPG instead of .jpg, you could use:

    RewriteRule (.*)\.jpg images/$1.jpeg [NC,L]
    Code (markup):
    The NC means No Case and will mean the regex matches .jpg and .JPG.

    Hopefully this will mean that you won't have to actually write out 1000 separate RewriteRule lines. If your images have completely changed their names in a random way and not just their locations or their names in a predictable way, then you'll probably have to write out all the 1000 lines.

    Another option would be to create 1000 symlinks, which would certainly take some of the processing load off serving files. In fact, if it's all random changes, that might be the best option.
     
    Ladadadada, Oct 14, 2007 IP