3

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.

1 Answer 1

8

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Minor elaboration on the <base> suggestion: it has to be specified before any relative URLs. If you specify it after one, such as after the <link> tag, it'll still fail.
But if it is treated like a directory why is it still processed as php?
@abruski Note that I said "your browser assumes .. ". Your browser is trying to include the external resources (according to a good guess of the base path), while your server is correctly serving the file.
Small nit: <link href="/... is generally called a root relative path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.