Are there differences between links

<a href="http://site.com/article-page">Статья</a> или <a href="/article-page">Статья</a> 

Ie how best to specify? because I call the full path in all the links, instead of how I understand the internal?

    4 answers 4

    For visitors to your site there is no difference. The difference arises in the following cases:

    1. You decide to change the site domain.
    2. You decide to change the protocol from HTTP to HTTPS.

    In this case, you will need to update all the links on the site. If you have static pages or content with static absolute links, the problem arises: you will need to update all the links on the entire site. This is fraught with errors, for example, if you skip any link, the navigation will break and the visitor will not find the page you need.

    If you generate links programmatically, for example, you have a constant "site domain" and you output it every time, rather than just copying the full address, then again there are no problems - you just need to change one link. Among other things, this approach allows you to place the site in a subfolder (links of the form /page will be in the root).

    Using different types of relative paths ( /page , page , //domain/page ) is a method that works when changing the domain and protocol regardless of the technology used, so it is usually given preference.

    • Thank you very much, I somehow did not think about it. I'll take a note. - webstackoverload

    If this is a link to one of the pages of the site you are working on, then the second option is better.

    The first option is absolute, the second is relative. If you specify an absolute path, and the site, for example, moves to another domain, the link will already be inactive. And if you just specify href = "/ article-page", then everything will work

      I’ll add from the point of view of optimization for search engines, the first option as a full link would be better to pass a link, otherwise Squidward is right, so summarizing I would put the site variable with the protocol (" http://site.ru ") and generated the links taking into account this variable, if the site's engine allows it, of course).

      • This can be realized, but the whole engine can be put at risk. So I think we will initially define the protocol, and then replace all the links, a lot of mind does not need to do this, check them for validity too. - webstackoverload

      it all depends on where your article is located and your html file itself, if you have an article from another source then you need to write a full address ( http://site.com/article-page ), if you have it (for example, the same folder where the html file is) then you can just write the file name, (or if not in the same folder then write the address of the article referring to the position of the Html file in the system)