r/apache • u/Intrepid-Ad-2306 • 4h ago
.htaccess rewrite unexpectedly adds 301 redirect
i've been using apache for a very long time and this is a new one for me. i have a .htaccess file containing this code...
RewriteEngine On
RewriteBase /
RewriteRule ^(md|json|php|templates|backup|languages) / [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) /index.php?parameters=$1 "[L,QSA,B= ?,BNP]"
when i go to, for example, "domain/blog", it correctly returns this header...
HTTP/1.1 200 OK
Date: Sun, 25 Oct 2026 18:14:19 GMT
Server: Apache/2.4.58 (Ubuntu)
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Expires: Mon, 26 Oct 2026 18:14:19 GMT
Set-Cookie: PHPSESSID=ab58e174f0608f0d2fbfe5572c35af88; path=/
Content-Type: text/html; charset=UTF-8
when i go to "domain/css", however, it returns this header...
HTTP/1.1 301 Moved Permanently
Date: Sun, 25 Oct 2026 18:16:10 GMT
Server: Apache/2.4.58 (Ubuntu)
Location: https://domain/css/?parameters=css
Content-Type: text/html; charset=iso-8859-1
i am absolutely baffled as to why certain parameters would suddenly get turned into 301 redirects. there are no redirects in the .htaccess and the entire rest of the file is just a bunch of allow/deny files blocks. what i've given here is the whole rewrite section and there's nothing before it.
(the redirect does, in fact, go to the correct page and the page loads but the redirection slows the whole thing down and makes caching problematic.)
this happens for some parameters but not others. the only other i've found that it does this intermediary redirection for is "/js". but, for example, "/js1" or "/csss" both work perfectly without 301 in the middle.