Question

I am looking for debugging ideas, not sure what is happening. All direct links, without the URI scheme (e.g., http://) don't work in an anchor. So assuming I am working on my localhost in the directory ./includes/:

<a href="www.example.com">Example<a> takes you to 127.0.0.1/includes/www.example.com

Whereas

<a href="http://www.example.com">Example<a> takes you to www.example.com

Using a file in a different directory also fails:

<a href="www.example.com">Example<a> takes you to 127.0.0.1/other/directory/www.example.com when starting in 127.0.0.1/other/directory

This is a basic HTML coded page. It is built with PHP, and has several links to .css files and .js files.

I have confirmed:

  • there isn't a <base> tag anywhere in the project files (netbeans project search)
  • No .htaccess files anywhere
  • No mod-rewrites going on anywhere.
  • This is a project on my localhost (127.0.0.1). However, other projects do not have the same issue.
  • When uploaded to the live server, I don't have the same problem.

In the Chrome debugger, the URI looks correct, but when I click on a link (such as www.example.com), it prepends the page information to that link, causing it to fail. Curiously, even when viewing source with CTRL-U, when I click on the link it takes me to the same incorrect URI!

This is true for firefox (and firebug) as well.

Any ideas on what is causing the bad link?

Was it helpful?

Solution

Your href attribute value is incorrect:

<a href="www.example.com">Example<a>

You're missing the protocol. Put http:// on the front:

<a href="http://www.example.com">Example<a>

Without it, how is the browser to know you didn't intend a file relative to the current one, named www.example.com? You must include the protocol.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top