Redirect sever ip to domain

Discussion in 'Apache' started by Devilfish, Feb 6, 2010.

  1. #1
    Hi folks,

    I have a dedicated server which hosts only one site. When I enter the ip address of the server into a browser I get the default apache index page.

    I would like to redirect the ip address to the domain. I tried to do it using htaccess rewrite rules but it doesn't appear to work or I've done it wrong.

    RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    Code (markup):
    Thanks for any help! :)
     
    Devilfish, Feb 6, 2010 IP
  2. chrisj383

    chrisj383 Well-Known Member

    Messages:
    754
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Can be chnaged in WHM, Account Functions -> Web Template Editor
     
    chrisj383, Feb 6, 2010 IP
  3. hvalle98

    hvalle98 Well-Known Member

    Messages:
    460
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Well, I am not an expert in this, but I suggest you could try using the Virtual Hosts module on your httpd.conf (I suppose you are using apache) to point that ip to a specific directory, where you can place the .htaccess file with the 301 redirection.

    Let me know if this works.
     
    hvalle98, Feb 6, 2010 IP
  4. subdivisions

    subdivisions Well-Known Member

    Messages:
    1,021
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    145
    #4
    Why would you do that? Just put the 301 directly in the VirtualHost entry, in the httpd.conf file.
     
    subdivisions, Feb 7, 2010 IP
  5. peterk92

    peterk92 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Setting up a VirtualHost is the correct way to do it but you could put a regular htaccess redirection on it.
     
    peterk92, Mar 7, 2010 IP