Jump to content

Getting Rid of localhost and Domain Name in href Path


OtagoHarbour
 Share

Recommended Posts

I am hosting a web site from home. My system has two layers: a web server (running Ubuntu 11.04) that is port forwarded through port 80 and has only index.php on var/www and an application server (running Ubuntu 11.10) that has everything else and is set up to only talk to the web layer server. index.php has the following line of code.

<li><a href="192.168.1.4/about.php">About</a></li>

This is a menu item that is supposed to call about.php which is located in var/www on the application server which has the local IP address 192.168.1.4. However, when I click the button associated with this menu item, it tries to access http://localhost/192.168.1.4/about.php and gives the error message

The requested URL /192.168.1.4/about.php was not found on this server.

If I go to the address box and manually delete the http://localhost/ part so the address box simply says 192.168.1.4/about.php then the about.php page on the application server shows up. Subsequently, when I click on a menu button associated with index.php then everything works fine. It seems like it starts by adding http://localhost/ to the specified address until I manualy delete it and then it leaves it out by default. The real problem comes when I try to access my site from another computer. I type in my domain name, say whatever.com, and the index.php page shows up. However when I click on the menu button, it tries to access http://whatever.com/...8.1.4/about.php and gives an error message. When I go to the URL box and manually delete http://whatever.com/, everything works fine. However I do not want the user to have to do this. Also, I am doing this from another computer on my home network so I am not sure what would happen from a remote computer. What is the best way to get the index.php file to simply use 192.168.1.4/about.php and not localhost/192.168.1.4/about.php, whatever.com/192.168.1.4/about.php etc. Many thanks in advance,Peter.

Link to comment
Share on other sites

for now it is taking it as relative url.prepend the prtocol if you want to point to different site. if you want to the url being changed if your site adrees change you can add $_SERVER['REMOTE_HOST'] in the place of host

Link to comment
Share on other sites

for now it is taking it as relative url.prepend the prtocol if you want to point to different site. if you want to the url being changed if your site adrees change you can add $_SERVER['REMOTE_HOST'] in the place of host
I tried chaning the php code to
<li><a href="$_SERVER['']/192.168.1.4/about.php">About</a></li>

but now it tries to accesshttp://localhost//$_SERVER['']/192.168.1.4/about.php I want it to just try to access192.168.1.4/about.php without all the preceeding stuff. Thanks,Peter.

Link to comment
Share on other sites

this is it

<a href="http://192.168.1.4/about.php">About</a>

$_SERVER['REMOTE_HOST'] will evaluate value only in php context <a href="<?php echo $_SERVER['REMOTE_HOST'];?>/about.php">About</a>

Edited by birbal
Link to comment
Share on other sites

I tried chaning the php code to
<li><a href="$_SERVER['']/192.168.1.4/about.php">About</a></li>

but now it tries to accesshttp://localhost//$_SERVER['']/192.168.1.4/about.php I want it to just try to access192.168.1.4/about.php without all the preceeding stuff. Thanks,Peter.

Someone gave me the answer. It should be <li><a href="http://192.168.1.4/about.php">About</a></li>
Link to comment
Share on other sites

this is it
<a href="http://192.168.1.4/about.php">About</a>

$_SERVER['REMOTE_HOST'] will evaluate value only in php context <a href="<?php echo $_SERVER['REMOTE_HOST'];?>/about.php">About</a>

Thanks. I'll try that and see if it works. The problem with what I had initially was that I did not specify the contect so it took the default. Thanks,Peter.
Link to comment
Share on other sites

Wait, all he is trying to do is have a working link to his pages depending on how he views them, right? Shouldn't <a href="about.php">About</a> work the same as <a href="<?php echo $_SERVER['REMOTE_HOST'];?>/about.php">About</a>?

Link to comment
Share on other sites

yes they works same but first one is relative address and second one is absolute address so it will print the host name .from the post of OP it seems like he wanted to print the host address too.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...