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):
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.
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.
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?
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.