HTML Navigation Error. How to handle www.website.com versus website.com? Correct navigation in html?

StackOverflow https://stackoverflow.com/questions/13428293

  •  29-11-2021
  •  | 
  •  

Question

I have the following html code:

<div id="page">
    <a class="topNavigationLink" href="http://MyOwnWebsite.com/">Home</a>
    <a class="topNavigationLink" href="page1.html">page1</a>
    <a class="topNavigationLink" href="page2.html">page2</a>
</div>

When i browse to www.MyOwnWebsite.com and then click on the navigation links, all works as expected.

But if i browse to MYOWnWebsite.com (no www) and then try to navigate to one of the pages i recieve a error :

Firefox can't find the file at http://MyOWnWebsite.com/page1.html.

Am i doing something wrong? what is the correct way to handle www.website.com versus website.com?

Was it helpful?

Solution 4

To fix this i did the following:

Went into my host gator control panel -> Clicked on domain redirect. added a permanent redirect from http://website.com to redirect to https://www.mysite.com.

This way every time the user goes mysite.com without the www , it will redirect them to the www.mysite.com and all the navigation will work from there.

OTHER TIPS

First thing you should do is to use relative links.

That being said, you should check your domain's DNS records, A records to have A "*" record, which takes all your subdomains, including "www" and points them at your server.

Or if you don't need all, you can put just "www".

You do this in your registrar's control panel.

What you have in your navigation are links without leading forward slash.

MAke your relative links /page_x.html and not just page_x.html

Here is one common mistake with navigation, when you are in at the current url

http://www.mywebsite.com/home/index.html

and you have an anchor tag in this form:

<a class="topNavigationLink" href="page1.html">page1</a>

When you click on this link, you are redirected to:

http://www.mywebsite.com/home/page1.html

This is because href="page1.html" is a relative link, and the base of the url is /home/

Solution:

if you want to access :

http://www.mywebsite.com/home/page1.html

You will have to add a forward slash to your link. Example:

<a class="topNavigationLink" href="/page1.html">page1</a>

This will have a base of the root domain /

If you have root (and ssh) access to your webhost, you should add a symbolic link to your www folder, in the htdocs directory. All directories in your htdocs folder are considered subdomains by your webserver. So if your DNS record points you to your server for the wildcard subdomain, your webserver will handle further processing of subdomains. So this symbolic link will make your server to load the same content for www.mysite.com and mysite.com.

cd /patch/to/htdocs
ln -s www mysite

Replace mysite by your domain name, but without the country suffix and www prefix. It should give you something like this:

[vhostxxxx@ssh:~/domains/mysite.com/htdocs]$ ls -l
total 3 
lrwxrwxrwx  1 vhostxxxx vhostuser  3 2012-11-10 12:47 mysite -> www
drwxr-xr-x+ 9 vhostxxxx vhostuser 20 2012-11-13 21:52 www`

Now, if I would browse to mysite.com, I would see the same site as www.mysite.com.

As for linking in your navigation:

`<div id="page">
    <a class="topNavigationLink" href="http://mysite.com/">Home</a>
    <a class="topNavigationLink" href="http://wwww.mysite.com">Home</a>
    <a class="topNavigationLink" href="wwww.mysite.com">Home</a>
    <a class="topNavigationLink" href="page1.html">page1</a>
    <a class="topNavigationLink" href="/page2.html">page2</a>
</div>`

This will link as follows (in some order):

  1. To the directory (or symbolic link) called mysite in your htdocs
  2. To the directory (or symbolic link) called wwww in your htdocs
  3. This is wrong. It will point at a page called wwww.mysite.com, which then should be located in the same directory as the page you linked it from. So if you linked it from htdocs/www/index.html it will point to htdocs/www/wwww.mysite.com. Always use http:// if your address includes a domain.
  4. To the page called page1.html, located in the same directory as the page you linked it from. If you linked it from htdocs/www/SomeTopic/page99.html it will point to htdocs/www/SomeTopic/page1.html
  5. To the page called page2.html, located in the document root. If you linked it from htdocs/www/SomeTopic/page99.html it will point to htdocs/www/page1.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top