|301 redirect for multiple pages|
| 11:55 am on Jun 11, 2007 (gmt 0)|
I have about 50 pages that I need to redirect. I have changed the internal structure of my site and found it necessary to rename many files. I've been told that I must use the .htaccess file and have been given a code. I don't understand though...how to achieve this for 50 pages. How do I write the code for 50 different redirects...one after the other? Do I need a space or specific character to separate them? Please advise.
Thanks in advance,
| 12:05 pm on Jun 11, 2007 (gmt 0)|
Hi and welcome to WebmasterWorld
Just leave the old ones and take them away when Google have spidered the new ones, it should be done very quickly theese days. It should have been very easy to redirect if you had a new domain, but i think you have to redirect eaxh one in this case.
[edited by: Ove at 12:06 pm (utc) on June 11, 2007]
| 9:17 pm on Jun 11, 2007 (gmt 0)|
Are you saying that I don't need to setup a 301 redirect for any of the renamed pages...Just publish the new ones?
| 2:40 am on Jun 12, 2007 (gmt 0)|
The answer depends on what you want to do.
First of all changing your filenames does not mean that you need to change your URLs. These are two different systems of referring to objects; Filenames refer to server files, and URLs refer to Web resources. The two need not be similar in any way, despite the fact that by default, the server maps URLs to filenames in such a way that the last part of the URLs and filenames look identical.
In brief, you can easily keep the old URLs and simply rewrite requests for those old URLs to the new filenames on the server. The links on your pages don't change, search engines see no difference, and you don't affect your page ranking or visitor's bookmarks in any way -- Again the URLs are not dependent on the server filepaths.
This is accomplished using the "internal rewrite" function of mod_rewrite, which can map requested URLs to arbitrarily-chosen server filepaths.
If you really want to redirect all those old ranked, listed, and bookmarked URLs, then 50 redirects, one per line, is the proper way to do it.
Note that if there was some organized, systemic change to your file organization, it is often possible to redirect (or rewrite) entire groups of old URLs to new URLs, using the magic of regular-expressions pattern-matching.
| 12:09 pm on Jun 12, 2007 (gmt 0)|
Thank you for your responses. I am new to this. If I understand correctly, the code to be added to the end of my current .htaccess file would be something like this for pages 1-3 of the 50 I'd like to redirect:
redirect 301 /the_old_page.htm http://example.com/the-new-page.htm
redirect 301 /the_old_page2.htm http://example.com/the-new-page2.htm
redirect 301 /the_old_page3.htm http://example.com/the-new-page3.htm
*This form may underline the above urls as a hypertext link-please disregard. I didn't underline them. (caught it in preview mode)
Please advise. thanks in advance.
[edited by: jdMorgan at 2:48 pm (utc) on June 12, 2007]
[edit reason] Use example.com to avoid linked URLs [/edit]
| 2:56 pm on Jun 12, 2007 (gmt 0)|
Well, for best portability, I'd recommend you type the directives exactly as they appear in the Apache mod_alias documentation, but otherwise they're correct.
Redirect 301 /the_old_page.htm http://example.com/the-new-page.htm
Redirect 301 /the_old_page2.htm http://example.com/the-new-page2.htm
Redirect 301 /the_old_page3.htm http://example.com/the-new-page3.htm
Now, I mentioned that you may not need 50 rules. Here's an example, treating your example URLs as if they were literally the real URLs:
RedirectMatch 301 ^/the_old_([^.]+)\.htm$ http://example.com/the-new-$1.htm
That will redirect *all* URLs of the form "/the_old_<something>.htm" to "/the-new-<something>.htm" with only one directive instead of fifty.
If your old URLs have such commonality, you can take advantage of it to reduce the number of redirect directives you need to write, test, and maintain.