0
votes

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]

1
All of this looks wrong. You're likely curing a symptom and not the case - e.g. relative vs absolute paths. - Jason McCreary
Can you post an example of a link to one of your css files? - Daniel Paul Searles
Link to CSS file = <link rel="stylesheet" href="style.css"> - user2534723
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". - IMSoP

1 Answers

1
votes

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

<base href="/">