htaccess redirect based on host ip

Discussion in 'Site & Server Administration' started by craigedmonds, Jan 12, 2011.

  1. #1
    Hi,

    I have a unique ip for one of my sites. This site uses SSL.

    When someone types http://theipaddress into their browsers they get a broken version of the site and an ssl error.

    My question is....how do I redirect someone from the ip to the url version of the web site using .htaccess.

    I was thinking that perhaps this would work...

    redirect 301 http://theipaddress https://%{HTTP_HOST}
    Code (markup):
    But it didnt.

    Any smart people out there who can help me with this?
     
    Last edited: Jan 12, 2011
    craigedmonds, Jan 12, 2011 IP
  2. robaid

    robaid Member

    Messages:
    126
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #2
    If your host supports rewrite, something like this should work:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    Code (markup):
     
    robaid, Jan 12, 2011 IP
  3. craigedmonds

    craigedmonds Notable Member

    Messages:
    705
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    235
    #3
    craigedmonds, Jan 12, 2011 IP