Should I use relative or absolute url on my website?

时光怂恿深爱的人放手 提交于 2021-02-05 05:44:07

问题


If I'm not moving my site around, any good reason for why I should use absolute URL's over relative?


回答1:


Absolute URL's will work no matter if you move the content from folder to folder, however each language will have a way to reference a BASE URL in one way or another.

For example if you have "test/1.html" as a URL on index.html it will redirect to /test/1.html however if you copy that link to /dom/index.html it will redirect to /dom/test/1.html

It would be best practice to use the base URL and then the relative URL e.g. {BASE URL}/test/1.html




回答2:


I tend to prefer using relative because if you ever make any changes to the site relative urls tend to be much more adaptable.

If you are talking about efficiency, there is no real difference between the two.




回答3:


If I'm not moving my site around [...]

This will come up one day. Even if you're just moving your site from one folder to another, you want the links to be relative. You may not think that will ever happen, but it's better to be safe than sorry.



来源:https://stackoverflow.com/questions/11688826/should-i-use-relative-or-absolute-url-on-my-website

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!