Question

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.

Was it helpful?

Solution

Use a relative path by removing the leading slash:

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

OTHER TIPS

Your styles or scripts must be relative to your current file.

If you use slash before any path, accessing it as local file will inform to your browser to lookup file on root path (c:).

In your development environment, you can use Apache mod_alias (Alias) for your application. It may be used according your server path configuration.

You can use:

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

or

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

or see RichieHindle's answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top