0

Alright so this is what the root of my site looks like:

  • assets
    • css
    • js
    • img
  • .htaccess
  • index.php
  • page1.php
  • page2.php
  • page3.php
  • style.css

My current .htaccess file works in the sense that it hides .php from the pages which is what i want. So i can access it from http://example.com/page2. But the problem is if i go to http://example.com/page2/ You can see the raw code without any CSS. I want to either redirect users to somewhere else OR have it show it correctly regardless of if there is a "/" or not.

Making it a directory is not an option. It has to be a PHP file in the root.

Current .htaccess file:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]

4
  • All of this looks wrong. You're likely curing a symptom and not the case - e.g. relative vs absolute paths. Commented Jul 10, 2013 at 18:29
  • Can you post an example of a link to one of your css files? Commented Jul 10, 2013 at 18:33
  • Link to CSS file = <link rel="stylesheet" href="style.css"> Commented Jul 10, 2013 at 18:40
  • The rewrite rule given specifically excludes URLs ending in /; does /page2/ definitely display page2.php, or is it some other content? The reason the CSS isn't displaying correctly is that href="style.css" means "a file called 'style.css' in the current URL directory; to the browser, the directory is http://example.com/page2/ not http://example.com/, as it doesn't know about the rewrite rules. You just need to use a path relative to the domain root instead: href="/style.css". Commented Jul 10, 2013 at 18:56

1 Answer 1

1

Change your css links to absolute URLs (the start with a /) or add this to the header of your pages:

<base href="/">
Sign up to request clarification or add additional context in comments.

Comments

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.