Forum Moderators: phranque

Message Too Old, No Replies

1 site, 2 domains. I need some sort of redirection

         

Michael85

5:03 am on Jan 12, 2009 (gmt 0)

10+ Year Member



I have a forum setup right now with about 4000 members, and I'm planning to change the domain name (long story). There are links such as:

[currentdomain.net...]
[currentdomain.net...]
[currentdomain.net...]

I need to find a way to make it so when people visit links like the above (using the old domain) it redirects to the new domain, like this:

[newdomain.com...]
[newdomain.com...]
[newdomain.com...]

I need it to do this on the fly, since we have thousands of links like the above.

I'm hoping this can be done using .htaccess

Thanks in advance,

-Michael

[edited by: Michael85 at 5:05 am (utc) on Jan. 12, 2009]

jdMorgan

6:44 am on Jan 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a simple redirect of one domain to another, and takes just one line of code -- Or maybe three, if you don't have any other working redirects in your .htaccess file.

Query strings pass unchanged through redirects, unless you take steps to change them. This is because they are data attached to URLs, and not actually part of the URLs. So that simplifies this matter considerably.

A quick look at our forum library, or a search of these forums for "redirect domain" should get you started...

Jim

g1smd

8:29 pm on Jan 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure that you redirect from both currentdomain.net and from www.currentdomain.net to the new domain.

Make sure that the newdomain.net also redirects to the www version of the new domain.

Make sure the redirect is a 301 redirect, and that you get to the target from any of the starting points in only one hop. That is, make sure that none of the inputs leads to any sort of Redirection Chain.

Michael85

10:40 pm on Jan 12, 2009 (gmt 0)

10+ Year Member



I've had a look around, and come up with this:

Edit the .htaccess file of the old domain to include this;

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [newdomain.com...] [R=301,L]:

Is this right?
I would really appreciate it if someone could correct the above, if it's wrong.

Thank you,

Michael

g1smd

10:49 pm on Jan 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That would work just fine if the old domain has its own separate hosting plan.

However, why pay for a complete hosting plan just to host a single file with just three lines in it?

I point all of the relevant domains at a single hosting plan, and then add a

RewriteCond
to call the redirect only if the "wrong" domain name was called.

Michael85

2:44 am on Jan 13, 2009 (gmt 0)

10+ Year Member



I appreciate your help on this, but I don't know how to do that. Could you please explain what I would need to insert into the .htaccess file for your suggestion to work for me?

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [newdomain.com...] [R=301,L]:

Thanks in advance,

Michael

[edited by: Michael85 at 2:45 am (utc) on Jan. 13, 2009]

jdMorgan

3:11 am on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Options +FollowSymLinks
RewriteEngine on
#
# If requested hostname is not [i]exactly[/i] "www.newdomain.com", then redirect to "www.newdomain.com"
RewriteCond %{HTTP_HOST} !^www\.newdomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Note: Removed spurious colon character following "[R=301,L]" in original post.

Jim

Michael85

4:23 am on Jan 13, 2009 (gmt 0)

10+ Year Member



Thank you, I'll give that a try soon.

How would I go about implementing this? My hosting plan allows multiple add-on domains, but when I register the add-on in CPanel, I have the option of where I want to create the folder for the new domain. Do I just point the new add-on domain to /public_html/, which is where my current domain is located?

Thanks again, I really appreciate the help!

Michael

jdMorgan

4:03 pm on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code goes in .htaccess in the web root (the "home page" folder) of your site.

If you point them all to the same filespace, then the above code will redirect all of them to www.newdomain.com

If you point each to its own filespace, then you'll need to add this (or similar) code at the root of each domain's space to do the redirect.

Jim

g1smd

7:55 pm on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I point everything at the one filespace and let the .htaccess file issue a redirect if the requested domain name was the wrong one.