301 redirect of old files and canonicalisation issues

Discussion in 'Apache' started by LawnchairLarry, Jul 8, 2008.

  1. #1
    I need to set up a .htaccess file that permanently redirects the URLs of a number of old files to those of the new files. Do I need to duplicate the list of files, i.e. one list of old files with their non-www URLs and one list of old files with their www URLs, or is there some code that can tackle this canonicalisation issue without having to list the URL redirects twice? Cheers for your help!

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^http://domain.tld/old-file-1.htm$ http://www.domain.tld/new-file-1.htm [R=301,NC,L]
    RewriteRule ^http://www.domain.tld/old-file-1.htm$ http://www.domain.tld/new-file-1.htm [R=301,NC,L]
    RewriteRule ^http://domain.tld/old-file-2.htm$ http://www.domain.tld/new-file-2.htm [R=301,NC,L]
    RewriteRule ^http://www.domain.tld/old-file-2.htm$ http://www.domain.tld/new-file-2.htm [R=301,NC,L]
    # Et cetera...
    Code (markup):
     
    LawnchairLarry, Jul 8, 2008 IP
  2. Dogs_and_things

    Dogs_and_things Active Member

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    What works for me is a simple thing like
    redirect 301 /old_file.html http://www.domain_name.com/new_file.html
    Code (markup):
    Only one line per file, every new file-name on a new line, nothing else.
     
    Dogs_and_things, Jul 8, 2008 IP
  3. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    437
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'll second what Dogs and things recommended (I was going to post the exact same code as well). Just make sure you replace old_file.html domain_name.com and new_file.html with the real old/new pages and domain name/TLD.
     
    Dan Schulz, Jul 8, 2008 IP
  4. LawnchairLarry

    LawnchairLarry Well-Known Member

    Messages:
    318
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Cheers for your replies! What about these three lines:

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine On
    
    Code (markup):
    Do these lines need to be included in the code?
     
    LawnchairLarry, Jul 10, 2008 IP
  5. Dogs_and_things

    Dogs_and_things Active Member

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    No,

    Apart from what I posted earlier you don´t need to add anything else.

    For every url you want to redirect you place a new line of code in your .htaccess, like this:

    redirect 301 /old_file1.html http://www.domain_name.com/new_file1.html
    redirect 301 /old_file2.html http://www.domain_name.com/new_file2.html
    redirect 301 /old_file3.html http://www.domain_name.com/new_file3.html
    Code (markup):
    old_file1.html, domain_name.com and new_file1.html need to be replaced by the actual names of your files en domain name.
     
    Dogs_and_things, Jul 10, 2008 IP
  6. LawnchairLarry

    LawnchairLarry Well-Known Member

    Messages:
    318
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Cheers for your reply! :)
     
    LawnchairLarry, Jul 11, 2008 IP