문제

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.

도움이 되었습니까?

해결책

Use a relative path by removing the leading slash:

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top