How do I 301 a domain (but keep rest of URL) to new domain?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I 301 a domain (but keep rest of URL) to new domain?

Post by simonmlewis »

Hi

We are moving a site from one domain to the other, but need to keep the rest of the URL.

ie. www.oldsite.co.uk/product/fgh/ert/11/test
Would now be: www.newsite.co.uk/product/fgh/ert/11/test

Is there a HTACCESS code I can pop in that will change the domain part of it?
I suspect it can be done in a PHP file, but also suspect it's possible in htaccess.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by requinix »

Check out the Redirect directive.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by simonmlewis »

Code: Select all

RewriteCond "%{HTTP_HOST}" "!^www\." [NC]
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)"      "http://www.%{HTTP_HOST}/$1" [L,R,NE]
??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by requinix »

No, "Redirect". Although you could use mod_rewrite to do it too (but not with that stuff you posted).
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by simonmlewis »

So how .. ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by simonmlewis »

That's not a 301.
I'm certain there will be a simple one line code for htaccess, whereby it can tweak the http and domain part, but leave the rest, and 301 it onto the new site.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I 301 a domain (but keep rest of URL) to new doma

Post by Celauran »

simonmlewis wrote:That's not a 301.
Go back and read it again. Specifically the bit about status.
Post Reply