开发者

How to handle stylesheet links when local and server directory structures don't match

开发者 https://www.devze.com 2023-04-08 17:51 出处:网络
The document root of my website is directly the server webroot (public_html), and not in a separate subdirectory. This creates a problem for me, because my local website is in a project folder (which

The document root of my website is directly the server webroot (public_html), and not in a separate subdirectory. This creates a problem for me, because my local website is in a project folder (which is required by my editor, NetBeans), which means that href links to stylesheets need to be of the form:

/projectfolder/stylesheets/stylesheet.css

But on the server, since the website is directly in the webroot, the href url would have to be:

/stylesheets/stylesheet.css

When I asked my host about this, they said I would have 开发者_运维百科to refactor my project to change all the stylesheet links. But I don't know; it seems kind of funny to have to refactor (then "unrefactor") the local website every time I want to upload it to the server. Any other solutions out there?


You don't have to use absolute paths to your stylesheets. Use relative paths instead. Then it won't matter where your files are hosted, so long as they stay in the same positions relative to each other.

0

精彩评论

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

关注公众号