Как включить браузер cache
для test.json, который переписал / генерируется через json.php?
К сожалению, test.json отвечает заголовками, которые установлены для \.php$
, а не \.json$
.
Как правильно применить правила .htaccess, чтобы test.json, сгенерированный json.php, был кэширован и при обновлении браузера вернул 304 Not Modified
? И почему заголовок ответа по-прежнему показывает Server: Apache
, когда я использую ServerSignature Off
?
test.json застрял на статусе 200 OK
, заголовки ответа:
Date Thu, 17 Feb 2011 10:24:44 GMT
Server Apache
Content-Encoding gzip
Vary Accept-Encoding
X-Content-Type-Options nosniff
Cache-Control private, max-age=0
Imagetoolbar no
Content-Length 88
Keep-Alive timeout=1, max=100
Connection Keep-Alive
Content-Type application/json; charset=UTF-8
json.php
<?php
header('Content-type: application/json; charset=UTF-8');
echo '{"tets":"json"}';
?>
httpd.conf
ServerTokens Prod
KeepAliveTimeout 1
.htaccess
Options -Indexes +FollowSymLinks -MultiViews
ServerSignature Off
php_value output_handler ob_gzhandler
AddType application/json .json
AddDefaultCharset utf-8
AddCharset utf-8 .json
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-httpd-php application/json
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_update_static No
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 5000000
mod_gzip_maximum_inmem_size 60000
mod_gzip_min_http 1000
mod_gzip_dechunk Yes
mod_gzip_handle_methods GET POST
mod_gzip_item_include file \.(php|json)$
mod_gzip_item_include mime ^application/x-httpd-php$
mod_gzip_item_include mime ^application/json$
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_include handler ^proxy-server$
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_send_vary On
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType application/x-httpd-php "access plus 0 second"
ExpiresByType application/json "access plus 1 day"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.php$">
Header set Cache-Control "private, max-age=0"
Header set Imagetoolbar no
</FilesMatch>
<FilesMatch "\.json$">
Header set Cache-Control "public, max-age=31536000"
Header append Vary Accept-Encoding
</FilesMatch>
FileETag None
Header unset ETag
Header unset X-Powered-By
Header set X-Content-Type-Options: nosniff
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test.json json.php [L,QSA]
</IfModule>