abruski
abruski

Reputation: 871

CSS dissapears when adding trailing slash to URL

The problem is that when I add a trailing slash at the address bar url localhost/register.php/ the CSS dissapears (is not applied anymore). CSS is in a separate file in a separate dir. Here is the structure:

Structure

CSS is invoked in header.html with <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> header.html is included in index.php with include 'includes/header.html';

Running apache under Windows 7.

Upvotes: 3

Views: 3175

Answers (1)

Rob W
Rob W

Reputation: 349012

When a trailing slash is added, your browser assumes register.php to be another directory, rather than a file. When relative URLs are specified, the external resource will be sought relative to the subdirectory register.php/ (because of the slash).

Example:

  • Before adding a slash:
    css/style.css > http://localhost/css/style.css
  • After adding a slash:
    css/style.css > http://localhost/register.php/css/style.css.

Fixing
To fix this issue, make use of absolute URLs. Either of the following:

  • <link href="/css/style.css" ... />
  • <link href="http://localhost/css/style.css" ... />
  • <base href="/register.php" /> (this tag has to be specified within the <head>

Upvotes: 8

Related Questions