<p>Craft doesn’t get involved in .htaccess redirects at all, so whatever it is, it’s going to be a server config thing.</p>
<p>Some things to check:</p>
<ul>
<li>Is this server actually using Apache and not Nginx?</li>
<li>Is <code>AllowOverride</code> enabled? (The Apache config that allows .htaccess files)</li>
<li>Is <code>mod_rewrite</code> enabled?</li>
</ul>

CC BY-SA 4.0
2022-01-19T11:09:48.600Z
Sorry, should've mentioned in the original question that both sites are running locally on MAMP using Apache.
Tyssen
CC BY-SA 4.0
2022-01-19T07:05:00.647Z
2022-01-19T07:05:00.647Z
Brandon Kelly
<p>I'm not sure whether this is a Craft problem or whether I'm just not seeing something wrong.</p>
<p>For a test site with a folder structure like:</p>
<pre><code>public
  assets
     css
</code></pre>
<p>I have this:</p>
<pre><code>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/(js|css)/(.+)\.\w+\.(js|css)$ assets/$1/$2.$3 [L,NC]
</code></pre>
<p>which works fine in that</p>
<pre><code>/assets/css/test.css
/assets/css/test.min.css
/assets/css/test.jhd8jdjdj.min.css
</code></pre>
<p>all resolve to the same file.</p>
<p>But on a Craft site whose directory structure is</p>
<pre><code>public
  _css
  _js
</code></pre>
<p>this results in a 404</p>
<pre><code>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(_js|_css)/(.+)\.\w+\.(js|css)$ $1/$2.$3 [L,NC]
</code></pre>
<p>for</p>
<pre><code>/_css/test.min.css
/_css/test.jhd8jdjdj.min.css
</code></pre>
<p>Both sites are running locally on MAMP using Apache.</p>
<p>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?</p>
<p>The full <code>.htaccess</code> looks like this:</p>
<pre><code>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]
</code></pre>
<p>There's actually a bunch of HTML5 Boilerplate stuff in there as well but the output is the same with or without it.</p>

CC BY-SA 4.0
2022-01-19T16:39:55.593Z
Can you post the ``.htaccess`` file in question? BTW your rules should go above the default Craft rules in the file…
RitterKnight
CC BY-SA 4.0
2022-01-20T01:46:14.910Z
@RitterKnight I've edited the question to include it.
Tyssen
<htaccess>
.htaccess not rewriting filenames
# .htaccess not rewriting filenames

(Asked by: username_0 on 2022-01-19)

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.

**Tags:** htaccess

> **Comments:**
> **username_1**: Can you post the ``.htaccess`` file in question? BTW your rules should go above the default Craft rules in the file…  
> **username_0**: @username_1 I've edited the question to include it.  

---

## 1 answers

### Answer by username_2 on 2022-01-19. Score: 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?

> **Comments:**
> **username_0**: Sorry, should've mentioned in the original question that both sites are running locally on MAMP using Apache.  

---

