Pregunta

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.

¿Fue útil?

Solución

Use a relative path by removing the leading slash:

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top