.htaccess conditional redirect rules

Discussion in 'PHP' started by vinayak.jd, Oct 10, 2007.

  1. vinayak.jd

    vinayak.jd New Member

    Joined:
    Oct 10, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have two domains ponting to the same IP. www.domain1.com & www.domain2.com. I want domain2.com to be redirected to the domain1.com permanently (i.e 301) with the condition, when anyone visit domain2.com, he will be directed to domain1.com.

    I have tried it with rewritecond, but the URL remains as domain2.com. I want it to change to domain1.com.

    Below is a code I tried,

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.domain2.com$
    RewriteRule index.html http://www.domain1.com [R=301]

    Is there any way to write code like.....
    Condition :
    Redirect 301 :


    Can anyone suggest the solution please...?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    With 301 Redirect the URL should change. visit go4expert.com and you will be redirected to the www version and the URL will change.
     
  3. vinayak.jd

    vinayak.jd New Member

    Joined:
    Oct 10, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Aggreed. But that is a simple redirect 301 rule.

    I want conditional rule in .htaccess file. I have a website with two different domains. but I want visitors to see domain1.com in address bar even if he types with domain2.com.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice