htaccess of front controller seems to block images, JavaScript, and CSS

154 Views Asked by At

I have a problem regarding my .htaccess file. It is placed in the root folder of my site together with the index.php (my front controller) and the folders regarding CSS, JavaScript, and images. The following is the URL-related content of my .htaccess file

# skip existent files
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule index.php - [QSA,L,C]
RewriteRule .* - [QSA,L]

# protect PHP files from the outside
RewriteCond %{REQUEST_URI} ^.*\.php$
RewriteRule ^.*\.php$ - [R=404,L]

RewriteCond %{REQUEST_URI} ^img/*$
RewriteRule ^img/*$ - [QSA,L]

# refer root to index.php
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ index.php [QSA,L]

# redirect 404 for non existent files
RewriteCond %{REQUEST_URI} ^(.*)\..*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\..*$ - [R=404,L]

# adjust the rest of the domains
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?site=$1 [QSA,L]

When I then open the website in the browser, it does not load the respective resources. If I click on "show image source", it immediately refers to the 404 page.

Do you have any idea which part I need to adjust to work around this problem? The root structure looks as follows

root
-.htaccess
-/css
-/js
-/img
-index.php

Thank you very much in advance! :)

EDIT 10/08/2021: I figured out that the problem was stemming from other RewriteRules which I put into the last section right before RewriteRule ^(.*)$ index.php?site=$1 [QSA,L], e.g.:

RewriteRule ^study-programmes/(.*)$ index.php?site=study-programmes&faculty=$1 [L]

However, I have several pages where I need specifically named parameter (such as faculty in the example above). What exactly do I need to adjust in order to make it work?

1

There are 1 best solutions below

2
attempt0 On

The image matching rules are not written correctly. The . is missing from the rule.

RewriteCond %{REQUEST_URI} ^img/.*$
RewriteRule ^img/.*$ - [QSA,L]