301 redirect .htaccess

Discussion in 'Programming' started by el_patron, Jan 27, 2011.

  1. #1
    Hey,

    I have a domain mydomain.net and mydomain.com. I want to use mydomain.com and redirect www.mydomain.net and mydomain.net to mydomain.com

    What is the best way to accomplish that with the .htaccess file?

    Thanks!
     
    el_patron, Jan 27, 2011 IP
  2. st1905

    st1905 Well-Known Member

    Messages:
    573
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Redirect 301 / http://mydomain.com/
    Code (markup):
    Put this in htaccess, thats it.


    or to redirect everything from that domain to new one

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*)  http://mydomain.com/$1 [R=301,L] 
    Code (markup):
     
    st1905, Jan 27, 2011 IP
  3. el_patron

    el_patron Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey,

    When I add your code I receive an error message (infinity loop). I added instead:

    RewriteCond %{HTTP_HOST} ^www.mydomain\.net$
    RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

    RewriteCond %{HTTP_HOST} ^mydomain\.net$
    RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

    Thats works also, but I thought that there is maybe a more elegant solution...

    Thanks!
     
    el_patron, Jan 27, 2011 IP