homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 redirect for multiple pages
gardener42

5+ Year Member



 
Msg#: 3364240 posted 11:55 am on Jun 11, 2007 (gmt 0)

Hello,
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,
John

 

Ove

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3364240 posted 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.

/Ove

[edited by: Ove at 12:06 pm (utc) on June 11, 2007]

gardener42

5+ Year Member



 
Msg#: 3364240 posted 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?

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3364240 posted 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.

Jim

gardener42

5+ Year Member



 
Msg#: 3364240 posted 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.
John

[edited by: jdMorgan at 2:48 pm (utc) on June 12, 2007]
[edit reason] Use example.com to avoid linked URLs [/edit]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3364240 posted 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.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved