HT Access - Mod Rewrite

If I use:

RewriteEngine On
RewriteRule ^.* controller.php

It will send all requests to the .php controller. But if controller.php included the css file (/assets/css/main.css), then it won’t work, as when the browser called it, it would just redirect to controller.php

Is there any way to fix this?

+3
source share
2 answers

You can add a condition to exclude URLs that can be mapped to actually existing files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.* controller.php

The keyword -fwill check if the absolute path in the %{REQUEST_FILENAME}path to the existing regular file in the file system !-fis only the reverse.

, , :

RewriteCond $0 !^(assets|foo|bar)/
RewriteRule ^.* controller.php

, RewriteRule ( $0) assets/, foo/, bar/. , RewriteRule:

RewriteRule !^(assets|foo|bar)/ controller.php
+6

:

RewriteEngine On

RewriteCond %{REQUEST_URI} !\.css$
RewriteRule ^.* controller.php

, .

0

Source: https://habr.com/ru/post/1725751/


All Articles