SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Switching my website to a new domain Rewrite rule and 301 Redirects

    Here is what i want to do.

    I have two domains.

    #1. www.old-domain.com
    #2. www.new-domain.com

    The old domains has been running for sometime and now i want to move the old website to a new domain name. I want to remove the old domain completely from my server so i only have one website running to not waste space. Under the new domain I want it so if someone enters in the old-domain.com domain no matter what page they try to go to it forces them to the new-domain.com.

    My sites are all hosted at rackspace.

    I'm thinking i would need to do some combination of .htaccess magic with rewrite rules and also maybe something at my registar as well on the old domain to point it to the new-domain.com ip address or something. I host my sites with Rackspace and register my domains with Godaddy.

    Anyone know what the Rewrite Rule may look like?
    MYCFMX (Under Construction)
    http://www.mycfmx.com/

    More from me - coming soon

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    RGD,

    You cannot access another domain's request so doing this from the new site is physically impossible ... unless they share the same DocumentRoot on the server. If that's the case, simply check whether the old domain was requested and then redirect:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} old-domain [NC]
    RewriteRule .? http://www.new-domain.com%{REQUEST_URI} [L,R=301]
    You'll have to keep the old domain for a while but, after a few months, you can let it lapse (or do something else with it).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh right, yeah that makes sense. I suppose i was thinking I could redirect the old domain to the new domain, but then if they went to internal pages they wouldnt get redirected.

    Here's what I'm going to do.

    Going to leave old-domain.com hosted on my server for about 3 months. From that domain I want to add a rule in the htaccess file that will redirect to the new-domain. But i also need a rule to handle the redirection if the user enters via a subpage, subsection and I'll want it to redirect to the same page on the new domain.

    So, for example, visiting old-domain.com/subpage2/somepage/ would redirect to new-domain.com/subpage2/somepage/ == essentially the same page but on the new domain. And of course, we also want to redirect all traffic from the homepage to the new-domain.com homepage.

    Will the rule you sent me there handle all of that too?
    MYCFMX (Under Construction)
    http://www.mycfmx.com/

    More from me - coming soon

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually, i found my answer. Actually pretty simple. I'm keeping the old domain active and then when people go to that site they will get redirected to the new domain and also if they need to get to the page too, all of that works. Simple one line rule.

    # alias redirect
    Redirect 301 / http://www.newdomain.com/
    MYCFMX (Under Construction)
    http://www.mycfmx.com/

    More from me - coming soon

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    RGD,

    Quote Originally Posted by RobbieGoD View Post
    oh right, yeah that makes sense. I suppose i was thinking I could redirect the old domain to the new domain, but then if they went to internal pages they wouldnt get redirected.

    Here's what I'm going to do.

    Going to leave old-domain.com hosted on my server for about 3 months. From that domain I want to add a rule in the htaccess file that will redirect to the new-domain. But i also need a rule to handle the redirection if the user enters via a subpage, subsection and I'll want it to redirect to the same page on the new domain.

    So, for example, visiting old-domain.com/subpage2/somepage/ would redirect to new-domain.com/subpage2/somepage/ == essentially the same page but on the new domain. And of course, we also want to redirect all traffic from the homepage to the new-domain.com homepage.

    Will the rule you sent me there handle all of that too?
    Yes. The {REQUEST_URI} variable would remain unchanged.

    Quote Originally Posted by RobbieGoD View Post
    actually, i found my answer. Actually pretty simple. I'm keeping the old domain active and then when people go to that site they will get redirected to the new domain and also if they need to get to the page too, all of that works. Simple one line rule.

    # alias redirect
    Redirect 301 / http://www.newdomain.com/
    BEST solution! Keep the old domain on its website (separate from the new domain) and use the mod_alias redirection ... as you have done.

    Note: Your original question implied that you wanted to use the .htaccess ON THE NEW SERVER to perform the redirection. I stand by my response that, in using the .htaccess on the new domain, they must be co-located. As you've found, even better to keep the old domain active on the old server and use mod_alias to perform the redirection. When it dies (in three months), the new domain will be "clean" (no changes to the .htaccess required).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •