1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to do 301 redirect to new domain via htaccess?

Discussion in 'Programming' started by DomainMagnate, Sep 26, 2015.

  1. #1
    I've switched domains and would like to redirect all pages like olddomain.com/somepage.html to newdomain.com/somepage.html - while preserving the same url structure. Could you show the htaccess code for it? thanks!
     
    DomainMagnate, Sep 26, 2015 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #2
    I haven't used this, just have it on file in case I need it for the same scenario. It's rather simplified, but it should redirect any requests on the old domain to the same location on the new domain.

    Redirect 301 (.*)$ http://www.newdomain.com/$1
    Code (markup):
     
    qwikad.com, Sep 26, 2015 IP
  3. DomainMagnate

    DomainMagnate Illustrious Member

    Messages:
    10,932
    Likes Received:
    1,022
    Best Answers:
    0
    Trophy Points:
    455
    #3
    just one line? Wouldn't that create some loop?
     
    DomainMagnate, Sep 27, 2015 IP
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #4
    Nothing is going to loop, but if you look for a SEO friendly (which really means very little today) way of doing the same thing, do this:

    RewriteEngine on
    RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
    Code (markup):
    The rule above redirects each page on an old domain to the same pages on a new domain.
     
    qwikad.com, Sep 27, 2015 IP
  5. Keteki

    Keteki Active Member

    Messages:
    112
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #5
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
    RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
    Code (markup):
     
    Keteki, Oct 9, 2015 IP