homepage Welcome to WebmasterWorld Guest from 54.227.62.141
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

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

Apache Web Server Forum

    
301 Redirect - simple?
BBonanza




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

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

 

g1smd




msg:4132551
 9:11 am on May 14, 2010 (gmt 0)

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.

BBonanza




msg:4132572
 9:52 am on May 14, 2010 (gmt 0)

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]

jdMorgan




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

"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

BBonanza




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

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

jdMorgan




msg:4134079
 3:16 pm on May 17, 2010 (gmt 0)

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

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved