1

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.

4

3 回答 3

0

Use a relative path by removing the leading slash:

<link rel="stylesheet" href="styles/main.css" type="text/css">
于 2013-03-29T18:21:23.037 回答
0

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.

于 2013-03-29T18:25:49.620 回答
0

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.

于 2013-03-29T18:28:15.673 回答