Search code examples
phphtmlwebabsolute-pathrel

How to use relative link instead of absoloute for localhost and remote server


My Apache web server root directory is set to "C:\webserver\webroot\AptanaProjects"

I want to be able to refer to a style sheet without putting in the absolute reference because I upload, using FTP, to a website.

The http://localhost/MovieDatabase/index.php file refers to http://localhost/MovieDatabase/styles/main.css

using:

<link rel="stylesheet" href="/styles/main.css" type="text/css"> 

which won't work because obviously I don't include the MovieDatabase part of the path.

How could I work around this to avoid putting in an absolute path? I don't want to change the webserver root directory to MovieDatabase as I have multiple projects.

Thanks.


Solution

  • Use a relative path by removing the leading slash:

    <link rel="stylesheet" href="styles/main.css" type="text/css">