Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

question about apache2, sorry but im really stuck

  • 04-12-2009 11:47AM
    #1
    Registered Users, Registered Users 2 Posts: 350 ✭✭


    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