468,512 Members | 1,544 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Map to different index page when user enters ip in apache2

107 100+
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.
Dec 29 '14 #1
5 20206
Luuk
1,043 Expert 1GB
you can do something with Rewrite see: http://httpd.apache.org/docs/current...d_rewrite.html
Dec 29 '14 #2
raamay
107 100+
any other alternatives?
Dec 29 '14 #3
Luuk
1,043 Expert 1GB
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.
Dec 29 '14 #4
raamay
107 100+
will it be fine if i created another virtual host to take care of the request from the ip address?
Dec 30 '14 #5
Luuk
1,043 Expert 1GB
That is also possible

The first server that has this line:
Expand|Select|Wrap|Line Numbers
  1. <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)
Dec 31 '14 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.