Welcome to WebmasterWorld Guest from 174.129.96.175

Forum Moderators: Ocean10000 & incrediBILL & phranque

301 Redirect - simple?

   
9:05 am on May 14, 2010 (gmt 0)

5+ Year Member



I want to do something that seems simple, but I can't find any info on how to do it.
I want to set up a 301 redirect in my .htaccess file for domain1.co.uk and all its pages to redirect to domain2.co.uk. I just want all the pages of domain1 to redirect to the homepage of domain2...is that possible? Do I have to do a rule for every single page or is the a blanket way of doing it?
Thanks :)
9:11 am on May 14, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

This is a trivial two lines of code.

One is a RewriteCond looking at HTTP_HOST.

The other is the RewriteRule for all paths (.*) redirecting to the other domain. Use [R=301,L] flags here.
9:52 am on May 14, 2010 (gmt 0)

5+ Year Member



Thats is what I used before but it only worked on the domain name. domainname.co.uk/pagename.htm went dead

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.domain2.co.uk/$1 [R=301,L]

Did I make a mistake?

[edited by: jdMorgan at 1:24 pm (utc) on May 14, 2010]
[edit reason] De-linked [/edit]

1:29 pm on May 14, 2010 (gmt 0)

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



"Went dead" is not a very helpful error description, but if both 'domains' are hosted in the same filespace on the same server, then you'll need that RewriteCond that g1smd specified:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^([^.]+\.)*domain\.co\.uk
RewriteRule ^(.*)$ http://www.domain2.co.uk/$1 [R=301,L]

Be sure to completely delete your browser cache before testing any changes to any server-side code.

Jim
1:19 pm on May 17, 2010 (gmt 0)

5+ Year Member



Hi Jim,

Thanks for the reply. Your code returned the following.

When I typed: www.domain1.co.uk
it forwarded correctly to: www.domain2.co.uk

When I typed in: www.domain1.co.uk/page1.htm
it forwarded to: www.domain2.co.uk/page1.htm (which created an error because the page isn't there)
I wanted it to forward to www.domain2.co.uk

I want all pages to forward to www.domain2.co.uk
Thanks
3:16 pm on May 17, 2010 (gmt 0)

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



Then replace the RewriteRule above with:

RewriteRule ^ http://www.domain2.co.uk/ [R=301,L]

However, you will now have created 'infinite duplicate content' and you may expect your search engine rankings to decline accordingly. Should a competitor discover that *any* URL can be requested from domain1 to show your domain2 home page, they can have quite a lot of fun with your search rankings as well...

I therefore strongly recommend that instead of taking this step, you implement proper 404 and 410 error handling on domain 2, displaying pages which explain that the requested resource is missing (404) or has been intentionally removed (410), and providing links to your home page, HTML site map page, major category pages, and site search facility, as applicable.

Jim
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month