Forum Moderators: phranque

Message Too Old, No Replies

how do you do a proper 301 re-direct?

         

mthorpe

12:23 am on Dec 8, 2004 (gmt 0)

10+ Year Member



i have changed servers and i need to re-direct my web sites so search engines will show the new url, but i do not know how to do a 301 re-direct in my html code. Can anyone tell me how to do this or give me some links within webamsterworld that someone else has already explained how to do a 301 re-direct?

jdMorgan

1:39 am on Dec 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



301 redirects are implemented by code on the server, not on an HTML page.

See Apache mod_alias [httpd.apache.org] and mod_rewrite [httpd.apache.org], or search WebmasterWorld for examples [google.com] to get you started.

Jim

mthorpe

2:27 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



how do i make a htacess 301 re-direct? i know it is supposed to be on my index and it's not html code, so what do i have to make to do this? Is it made on note pad as a txt file? I havn't got a clue!

jdMorgan

5:52 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope you'll read the references posted above, and in our charter.

The redirect code goes in a file, usally called ".htaccess" (maybe just "htaccess" on windows machines) in any directory on your site. It's scope is determined by which directory you put it in. If you put it in your Web root directory (where your "home page" is, then it can affect all requests all requests to your site. If you put it in a subdirectory, it can affect only requests to that subdirectory and its children.

A simple 301 redirect from foo.html to bar.html:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^foo\.html$ http://www.example.com/bar.html [R=301,L]

Jim

mthorpe

11:46 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



so if i us it in my root directory, does it effect just the index.html or all of my .html web sites. i have a web hosting account and i have many .html web sites off of it. will just one 301 re-direct cover all of my .html sites? i have moved to a different server and i wish to get my web sites that are on search engines to recognize the new server and all my .html web sites.

jdMorgan

11:58 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



so if i us it in my root directory, does it effect just the index.html or all of my .html web sites. i have a web hosting account and i have many .html web sites off of it. will just one 301 re-direct cover all of my .html sites? i have moved to a different server and i wish to get my web sites that are on search engines to recognize the new server and all my .html web sites.

Note that I said "your Web root directory, as in the directory where each sub-site's robots.txt file would be located.

The details of the answer depend on your exact set-up. If you are using domain forwarding or a "control panel" setup on your old server, then you may need to put an .htaccess file in each sites' subfolder... It all depends on precisely how the old sites are mapped into the filespace of the old server, and whether you have direct access to that "mapping" mechanism. If not, then one .htaccess per site will likely be required.

I should also point out that if your domain names have not changed, then all you need to do is to update the DNS records that point to your old server to point to the new server; You won't need redirects at all.

For redirecting all pages on one domain to the same page on another domain, you can use:

RewriteRule (.*) [new_domain.com...] [R=301,L]

-or-

Redirect 301 / [new_domain.com...]

These are directives of mod_rewrite and mod_alias, respectively, and accomplish the same thing. mod_rewrite is more flexible, while mod_alias is simpler.

Jim

mthorpe

3:56 am on Dec 18, 2004 (gmt 0)

10+ Year Member



jdmorgan: i got my 301 re-direct to work, thanks. just curious now to how long it takes search engines to recognize this and how long roughly (google and yahoo) search engines will file the new url and change it in their search results?