Click here to Skip to main content
15,937,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there.

I recently moved my web application onto the server with the href tag giving me hard times. Locally my files are placed in the root folder. But on the server it's placed in another folder. When I call the href tag from one page to go to another it gives an error saying the page is not found which seem to be correct.

I tried <a><\a>, and also <a><\a>.

Both ways work fine locally on my machine but not on the server.

Why is this happening and is there a work around? I thought of replacing my html code with jquery to open other pages.

Any advise will do please.

Regards
Posted
Updated 29-Jun-12 11:04am
v2
Comments
R. Giskard Reventlov 29-Jun-12 17:05pm    
Quite a confused question. Be very specific and display the code where it is going wrong.

1 solution

There is no href tag. href is an attribute of the a tag. a is for anchor.
Tags are closed with a / not a \ so
<a href="example.com">Example</a>
is valid.

Your problem is that you're linking to your files incorrectly.

Throughout your solution you need to consistently link to locations in your own directoy structure. If you're never going to move your project you can always set the href attribute to
HTML
<a href="/myproject/mypage.html">Example</a>

You have to realize here that the / in the beginning of the path means the browser will look to the root of the website. So no matter what page you're on, for example.com/this/is/my/app/index.html any link on this page that specifies
HTML
<a href="/myproject/mypage.html">Example</a>
will always point to example.com/myproject/mypage.html

You specify the current directory like so
HTML
<a href="myproject/mypage.html">Example</a>
this will point to example.com/this/is/my/app/myproject/mypage.html when the user is on example.com/this/is/my/app/index.html

So links starting with / are absolute and they link to the root of the current site if you omit the beginning / your link is relative to the current path.

You can also specify
HTML
<a href="./myproject/mypage.html">Example</a>
to point to the current directory.

Additionally you can specify
HTML
<a href="../myproject/mypage.html">Example</a>
this will move you up one directory. So the link above on the page example.com/directory/index.html will point to example.com/myproject/mypage.html.

Keep in mind that you can combine ../ with one or more ../ to move up more than one directory.

This
HTML
<a href="../../myproject/mypage.html">Example</a>
is totally valid and will move you up two directories.

I want to take this a little further. When you see an address example.com/article.html?id=101 this is passing a GET variable named id with the value 101 to article.html residing on the root directory of the webserver. You can use GET vars on a directory index. A directory index is a default file that's served by the server when no file is specified. So example.com when requested the server will load the default file generally index or default .php or .htm or .aspx or whatever. So the link example.com?id=101 passes a GET variable with the name id and value 101 to the directory index of example.com.
 
Share this answer
 
v7
Comments
Sandeep Mewara 30-Jun-12 6:42am    
5!
Nathan Stiles 30-Jun-12 13:56pm    
Thank you!
DJAppleboy 1-Jul-12 11:27am    
I tried all that with no success. Also tried
DJAppleboy 3-Jul-12 1:56am    
href="example.com"

That worked for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900