Jump to content
Sign in to follow this  
OtagoHarbour

Getting Rid of localhost and Domain Name in href Path

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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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>

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Just prepend http:// to the URL.

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

Share this post


Link to post
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>?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...