开发者

Should I use ./ or index.html for the hyperlink reference on my 'home' links?

I have a website with a 'home' link like many do and I am wondering whether I should do:

<a href="./">Home</a>

or

<a href="index.html">Home</a>

Obviously my homepage is contained in the index.html file. I have the first option implemented right now and it seems to work, but I am not sure what the preferred practice is or if there are any drawbacks to 开发者_JAVA百科one or the other.

I appreciate any help!


Using href="/" may require the browser to submit two requests. The first to "/" which is redirected at the server to "index.html". If it's not a 302 redirect, then there may be some potential search indexing implications, though that's subjective voodoo that may not apply.

The other issue is if your server just returns the contents of index.html for "/". When that is true your site will have two different URLs for the same resource. Not having canonical URLs for the same reference will affect your search performance.

While linking to "/" may offer some flexibility in that you can change it in the future, the difference between index.html and index.php is usually a significant architectural change and "future proofing" against is pointless. If you're switching to a dynamic site in the future, you'll be updating all your home links anyway...so no need to optimize for what won't ever happen.


Of the two href="/index.html" is the better choice. href="./" will not work reliable because of the dot.

href="/" is the most flexible because it allows you to change to a different index page (index.php, index.asp, etc) later without updating your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜