Map to different index page when user enters ip in apache2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raamay
    New Member
    • Feb 2007
    • 107

    Map to different index page when user enters ip in apache2

    Hello Experts, I have setup two virtual host pointing to same content mapped to ip 192.168.1.100. Everything works fine. But now my requirement is that when user enters the ip address instead of the domain name, the server should serve a different page instead of the index page of the domain. For now if i enter the domain name http://test.com and when i enter http://192.168.1.100, I am served with the index.html page of virtual host. Now, what i want is that when the user enter http://192.168.1.100, the server should serve default.html.

    http://test.com ---> index.php
    http://192.168.1.100 ---> default.html

    The above is the summary as to what i want. Please advice me how to go about.

    By the way I am using Ubuntu 14.04 LTS and Apache 2.4.7 for your kind information

    ** Sorry for posting in the wrong place. I would like to request the admin to kindly post it in the apache forum.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    you can do something with Rewrite see: http://httpd.apache.org/docs/current...d_rewrite.html

    Comment

    • raamay
      New Member
      • Feb 2007
      • 107

      #3
      any other alternatives?

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        Yes, you can check for referrer in you index.php, and forward the request to default.html

        If $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME'] are the same, you are getting there via ip-address.

        To forward the request, use info from this page.

        Comment

        • raamay
          New Member
          • Feb 2007
          • 107

          #5
          will it be fine if i created another virtual host to take care of the request from the ip address?

          Comment

          • Luuk
            Recognized Expert Top Contributor
            • Mar 2012
            • 1043

            #6
            That is also possible

            The first server that has this line:
            Code:
            <VirtualHost *:80>
            will serve the requests that are not served by a later defined ServerName
            (see: http://httpd.apache.org/docs/2.2/vhosts/examples.html)

            Comment

            Working...