Engin
Engin

Reputation: 13

using slash in htaccess makes css files not to load

first, i'm trying to find an answer to this like 3 nights :) If there's answer of this, i couldn't find or understand.

My question is simple:

I want to split get parameters with slashes. And use this globally in my script.

in htaccess, i wrote this;

RewriteRule ^(.*)/(.*) index.php?param1=$1&param2=$2 [NC,QSA,L]
RewriteRule ^(.*) index.php?param1=$1 [NC,QSA,L]

but this blocks (or sth like that) css files. when browser loads page, css file links looks normal but browser can't reach them (because of htaccess gets directories as parameters)

Thank you for your helps

edit: my full .htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

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


RewriteRule ^(.*)/(.*) index.php?param1=$1&param2=$2 [NC,QSA,L]
RewriteRule ^(.*) index.php?param1=$1 [NC,QSA,L]

Upvotes: 0

Views: 204

Answers (2)

Panama Jack
Panama Jack

Reputation: 24448

Make sure both your rules look like this. Conditions only work for the first rewrite rule following them.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*) index.php?param1=$1&param2=$2 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?param1=$1 [NC,QSA,L]

Also use absolute paths for your CSS files or put a / before the file path.

Upvotes: 2

rwacarter
rwacarter

Reputation: 2004

By putting this above the rules:

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

It checks if the files already exist (eg the CSS files) and therefore won't try to rewrite or redirect them.

Upvotes: 0

Related Questions