我正在使用all in one日历插件fron time.ly,它需要4到5秒钟来动态创建css文件http://www.example.com/?ai1ec_render_css=1401363227&ver=2.0.9
这破坏了我网站的性能,因此我想将以上内容指向我使用htaccess重写创建的http://www.example.com/wp-content/uploads/calendar.css
静态CSS页面。
但是,尽管经过大量测试以及对SO和Google的大量搜索,我还是无法使其正常工作。
这是相关的部分:
RewriteBase /
RewriteCond %{QUERY_STRING} ai1ec_render_css=(.*)
RewriteRule ^(.*)$ /wp-content/uploads/calendar.css? [L,QSA]
有关信息,这是整个htaccess文件...
#AuthType basic
#AuthUserFile "/path/to/passwd"
#AuthGroupFile /dev/null
#AuthName "Site Undergoing Essential Maintence - Back Soon"
#Require valid-user
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteCond %{QUERY_STRING} ai1ec_render_css=(.*)
RewriteRule ^(.*)$ /wp-content/uploads/calendar.css? [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
php_value upload_max_filesize 8M
php_value post_max_size 4M
php_value max_execution_time 300
php_value max_input_time 300
php_value memory_limit 4M
<IfModule pagespeed_module>
ModPagespeed on
# using commands,filters etc
</IfModule>
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
最佳答案
从RewriteRule ^(.*)$ /wp-content/uploads/calendar.css? [L,QSA]
中删除第一次出现的“ /”-这应该可以解决问题。
您已经定义了RewriteBase,但是您的RewriteRule告诉浏览器转到该文件夹下面的文件夹,然后进入wp-content/...
,该文件夹不会将其定向到相关页面。
关于css - htaccess重写无文件名的查询字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23933166/