Home > Back-end >  CSS/JSS loading problem with htaccess URL rewrite
CSS/JSS loading problem with htaccess URL rewrite

Time:11-06

Hello I've an app that's supposed to filder the urls with 3 arguments - Module / View / Id - but then, had to add the base html tag to sort out the css/jss url files, but now I have an issue where css/jss files are not loaded due to the redirect of the htacccess.

Htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Module
RewriteRule ^([^/] )/?$  index.php?module=$1 [NC,L]

# Module/View
RewriteRule ^([^/] )/([^/] )/?$ index.php?module=$1&view=$2 [NC,L]

# Module/View/Id
RewriteRule ^([^/] )/([^/] )/([^/] )/?$ index.php?module=$1&view=$2&id=$3 [NC,L]

Options  Indexes
Options  FollowSymlinks

Head files:

<base href="http://localhost/mycbsv2/">
        <!--begin::Fonts-->
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" />
        <!--end::Fonts-->
        <!--begin::Global Stylesheets Bundle(used by all pages)-->
        <link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
        <!--end::Global Stylesheets Bundle-->

The problem is if you go to the css file url, it does not load it as it's searching the file as a module (because of the url)...

enter image description here

Is there a way to add an exception to not filter the url when searching for files?

The issue might also come since all views of the app are managed from the index.php file.

CodePudding user response:

Rewrite conditions only apply to the very next rule. You have a rewrite condition that excepts actual files from your rewrite, but you only make that exception for the first of your three rules. You just need to repeat the conditions for each rule:

RewriteEngine On

# Module
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/] )/?$  index.php?module=$1 [NC,L]

# Module/View
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/] )/([^/] )/?$ index.php?module=$1&view=$2 [NC,L]

# Module/View/Id
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/] )/([^/] )/([^/] )/?$ index.php?module=$1&view=$2&id=$3 [NC,L]

Options  Indexes
Options  FollowSymlinks
  • Related