Welcome to WebmasterWorld Guest from 54.166.54.215

Forum Moderators: Ocean10000 & incrediBILL & phranque

Redirect old domain to new domain

   
2:38 pm on Jul 29, 2010 (gmt 0)

5+ Year Member



I have to move my website to a new domain and I am concerned about doing it smoothly. I understand that I need to change .htaccess file to redirect from the old to the new, but my concern lies in that I have an existing file with rewrite conditions in place that I want to keep intact. Not sure if I need to keep everything the same with the domain or do I use the new domain for the following:

DefaultType application/x-httpd-php

AddHandler x-httpd-php .php4
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ [olddomain.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^olddomain\.com
RewriteRule ^(.*)$ [olddomain.com...] [R=permanent,L]
rewriterule ^ama/([A-Za-z0-9]+)$ /includes/amazon.php?id=$1


Another question is where in the order of things do I put the following for the redirect to the new website? Or does order not matter?

RewriteCond %{HTTP_HOST} olddomain.com [NC]
RewriteCond (.*) [newdomain.com...] [R=301,L]

Thanks for any help on this. It is appreciated.
1:09 am on Jul 31, 2010 (gmt 0)

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



Change "olddomain" in your existing rules to "newdomain."

Put your new "catch-all" domain redirect rule ahead of your last rule -- that is, this new redirect will be the last external redirect, and then your last rule does internal rewrites only.

Jim
2:37 pm on Aug 2, 2010 (gmt 0)

5+ Year Member



Thanks for the help JD. You are always of great service.

Does this rule look correct, by the way?

RewriteCond %{HTTP_HOST} olddomain.com [NC]
RewriteCond (.*) [newdomain.com] [R=301,L]
RewriteRule (.*) [newdomain.com...] [R=301,L]

or should I use:

RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ [newexample.com...] [R=301,L]

or can I skip the RewriteCond statements all together and just use:

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

or

RewriteRule ^(.∗)$ [newdomain.com...] [R=301,L]

Seems like there are several ways to slice this onion.

Thanks in advance.
11:25 pm on Aug 2, 2010 (gmt 0)

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



All are flawed in one way or another. Try:

# Externally redirect all requests for non-blank non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} ^!(newdomain\.com)?$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

Jim
8:55 pm on Aug 10, 2010 (gmt 0)

5+ Year Member



This is what I have thus far:

DefaultType application/x-httpd-php

AddHandler x-httpd-php .php4
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ [newsite.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^newsite\.com
RewriteRule ^(.*)$ [newsite.com...] [R=permanent,L]
RewriteCond %{HTTP_HOST} !^www\.newsite\.com
RewriteRule (.*) [newsite.com...] [R=301,L]
rewriterule ^ama/([A-Za-z0-9]+)$ /includes/amazon.php?id=$1


Which lines are you saying i should replace with the following:

# Externally redirect all requests for non-blank non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} ^!(newsite\.com)?$
RewriteRule ^(.*)$ [newsite...] [R=301,L]


Thanks Jim
1:18 am on Aug 11, 2010 (gmt 0)

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



It should look like this:

DefaultType application/x-httpd-php
AddHandler x-httpd-php .php4
#
Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect direct client requests for "/index.php" or
# "/index.php4" in any subdirectory to "/" in that same directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/\ ]+/)*index\.php4?\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)index\.php4?$ http://newsite.com/$1 [R=301,L]
#
# Externally redirect all requests for non-blank non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} !^(newsite\.com)?$
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
#
# Internally rewrite "/ama/<id>" URL requests to amazon script filepath, passing <id> value in query string
RewriteRule ^ama/([A-Za-z0-9]+)$ /includes/amazon.php?id=$1

Note the comments. They are every bit as important as the code. If these comments don't say exactly what you want to do, then the code is wrong...

Jim
4:07 pm on Aug 16, 2010 (gmt 0)

5+ Year Member



Thanks for the help Jim. I had one last question.

It seems that you left out one of the condition/rules that I had in my .htaccess:

RewriteCond %{HTTP_HOST} ^newsite\.com
RewriteRule ^(.*)$ [newsite.com...] [R=permanent,L]

Was this because it was redundant and therefore combined with another in your final solution? Honestly, I can't remember what the above does.

p.s.

I've learned a valuable lesson for further websites...always use comments.
4:15 pm on Aug 16, 2010 (gmt 0)

5+ Year Member



Hi again Jim.

I got an error when using your solution:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Thanks in advance.
9:51 pm on Aug 16, 2010 (gmt 0)

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



The final rule needs an [L] flagged added for sure.

The missing rule appears to be catered for in other code.

Check the code carefully, do you want the www included or omitted in your target URL?
2:08 pm on Aug 17, 2010 (gmt 0)

5+ Year Member



Hi Jim:

Basically what I want in my code is the following:

# Redirect direct client requests for /index.php in any directory to "/" in that directory

# Redirect direct client requests to remove .php extensions

# Redirect all non-blank non-canonical hostname requests to canonical hostname

# Redirect to new website from old website

# Redirect the /ama urls to the amazon.php file


The code I provided seems to work for everything I want and Google seems to be understanding. At this point, my rankings have not been affected too much (a couple spots down), which is pretty good thus far.

My initial question was whether my code was efficiently written. What I did was copy the code from your previous answer and pasted it into my htaccess file, making the changes to reflect my site name. I do want it to go to www versus without www.

I've always wondered why when you post code in this forum it gets messed up? Wish there was a way around that so people can share code verbatim. Maybe you posted the answer and it had characters in it that I am not to have in the code, like the "( )"? Just a guess.

Thanks for your help.

Michael
7:30 pm on Aug 17, 2010 (gmt 0)

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



Your original example code redirected to www.example.com but jd's example code redirected to example.com, without www, and that difference is crucial.

Check which one you want to redirect to and make sure the code you use is exactly right. It will take forever to fix things, should you implement code that redirects in the 'wrong direction'.
4:11 am on Aug 19, 2010 (gmt 0)

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



http://example.com and http://www.example.com are recognized as example domains and won't "get messed up" if you use them in posts. Otherwise, URLs will trigger the forum's auto-linking code, and you see the results...

URLs inside contiguous [ code ] sections will not be autolinked.

Where it is necessary outside of a [ code ] section to use other domains for clarity (such as http://newdomain.com and http://olddomain.com), you can 'break' the autolinking by including [bold] or [italic] bbCode pairs or by using the [ smilestopper ] code tags after the http: part of the URL.

Jim
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month