1

This is my file structure: you can see it here or

-resources/
--css/
---index.css
-src/
--views/
---main.view.php
--main.php
index.php
.htaccess

This is my .htaccess:

RewriteEngine On

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

This is how I include the CSS in the view

<link rel="stylesheet" href="resources/css/index.css">

Problem: When I Include main.php (that includes the view) in index.php the CSS does not work no matter where I place the index.css. Any hint?

1
  • Try adding a slash before the CSS path. The way it is currently written should work only for the example.com/index.php Commented Jul 10, 2021 at 15:40

1 Answer 1

3

You need to add in a rule to exclude rewriting of assets

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! You probably saved me hours of research <3
Do you know how to keep the url in the ?url parameter? I don't fully understand that Cond
is it not working? the URL should be kept as a parameter
It is but not when I write something like /actions/comment. Anyway u solvec my initial question. I will check the anwer.

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.