1

I'm not sure whether this is a Craft problem or whether I'm just not seeing something wrong.

For a test site with a folder structure like:

public
  assets
     css

I have this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/(js|css)/(.+)\.\w+\.(js|css)$ assets/$1/$2.$3 [L,NC]

which works fine in that

/assets/css/test.css
/assets/css/test.min.css
/assets/css/test.jhd8jdjdj.min.css

all resolve to the same file.

But on a Craft site whose directory structure is

public
  _css
  _js

this results in a 404

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(_js|_css)/(.+)\.\w+\.(js|css)$ $1/$2.$3 [L,NC]

for

/_css/test.min.css
/_css/test.jhd8jdjdj.min.css

Both sites are running locally on MAMP using Apache.

So is this a problem specific to Craft? Or can I just not see what's wrong with the rewrite rules on the Craft site?

The full .htaccess looks like this:

RewriteEngine On

# Asset path rewriting
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(_js|_css)/(.+)\.\w+\.(js|css)$ $1/$2.$3 [L,NC]

# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]

There's actually a bunch of HTML5 Boilerplate stuff in there as well but the output is the same with or without it.

2
  • Can you post the .htaccess file in question? BTW your rules should go above the default Craft rules in the file… Jan 19, 2022 at 16:39
  • @RitterKnight I've edited the question to include it.
    – Tyssen
    Jan 20, 2022 at 1:46

1 Answer 1

2

Craft doesn’t get involved in .htaccess redirects at all, so whatever it is, it’s going to be a server config thing.

Some things to check:

  • Is this server actually using Apache and not Nginx?
  • Is AllowOverride enabled? (The Apache config that allows .htaccess files)
  • Is mod_rewrite enabled?
1
  • Sorry, should've mentioned in the original question that both sites are running locally on MAMP using Apache.
    – Tyssen
    Jan 19, 2022 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.