Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of Apache rules for static caching wrong? #1587

Open
marnickmenting opened this issue Jan 14, 2025 · 0 comments
Open

Order of Apache rules for static caching wrong? #1587

marnickmenting opened this issue Jan 14, 2025 · 0 comments

Comments

@marnickmenting
Copy link

On https://statamic.dev/static-caching#apache it shows .htaccess rules for redirecting to the static files. I believe the order these lines is wrong and therefore never hits the actual cache files.

This is in the docs:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !live-preview
RewriteRule ^ index.php [L]
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} live-preview
RewriteRule ^ index.php [L]
 
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* static/%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
</IfModule>

I kept receiving this message in Laravel logs:
Static cache loaded [..url..] If you are seeing this, your server rewrite rules have not been set up correctly.

I changed it to this, and now the message does not show up anymore:

<IfModule mod_rewrite.c>
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* static/%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !live-preview
RewriteRule ^ index.php [L]
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} live-preview
RewriteRule ^ index.php [L]
</IfModule>

I also added the missing IfModule starting tag. I would happily make a merge request, but I wanted to check if I am not missing something obvious as I don't see any issues raised by other users about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant