Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

question about apache2, sorry but im really stuck

Options
  • 04-12-2009 11:47am
    #1
    Registered Users Posts: 343 ✭✭


    hey you guyssss,

    can i ask an apache question if you dont mind!

    i have an apache2 webserver running on unbuntu and i want to stop the website loading if people go to the URL using the IP address.

    so http://1.1.1.1/mysite wont load. is there any config is apache2 to do this?

    i have been reading about rewrites and virtual hosts, but am not having any luck.

    cheers


Comments

  • Closed Accounts Posts: 658 ✭✭✭pontovic


    hey you guyssss,

    can i ask an apache question if you dont mind!

    i have an apache2 webserver running on unbuntu and i want to stop the website loading if people go to the URL using the IP address.

    so http://1.1.1.1/mysite wont load. is there any config is apache2 to do this?

    i have been reading about rewrites and virtual hosts, but am not having any luck.

    cheers

    Hey,

    Hope this is of some assistance. Are you familiar with URL rewriting - also known as rewrite rules ? If not, then read about them. Google will bring up some good results.

    What you could do is the following:

    1) Create a file named .htaccess and add the following contents.
    RewriteEngine on
    RewriteCond %{HTTP_HOST}          ^([0-9\.]+)$                      [NC]
    RewriteRule  ^(.*)$                       http://www.yoursite.tld        [R=301,L]
    

    What that does is it matches the web address the user has entered in, in this case, the IP address (taken from HTTP_HOST). It checks to see if it's an IP address ^([0-9\.]+)$ (the regular expression may be wrong in which case you will have to figure it out). If it matches, that means someone is visiting the page using the IP address and not the domain name. If that is the case, any page on the site ^(.*)$ that is visited with the IP address as the host name will trigger a redirect to http://www.yoursite.tld [R=301,L].

    When the site is loaded again, the HTTP_HOST variable will not be an IP address and the user can proceed as normal.

    Good luck with it.


Advertisement