<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/* https://thk.kanzae.net/net/itc/t2286/ */
function haup_site_optimize_code_add_to_htaccess($rules) {
	$content = "# ETags(Configure entity tags) を無視する設定\n" .
		"<ifModule mod_headers.c>\n" .
		"Header unset ETag\n" .
		"</ifModule>\n" .
		"FileETag None\n" .
		"# Enable Keep-Alive を設定\n" .
		"<IfModule mod_headers.c>\n" .
		"Header set Connection keep-alive\n" .
		"</IfModule>\n" .
		"# MIME Type 追加\n" .
		"<IfModule mime_module>\n" .
		"AddType text/cache-manifest .appcache\n" .
		"AddType image/x-icon .ico\n" .
		"AddType image/svg+xml .svg\n" .
		"AddType application/x-font-ttf .ttf\n" .
		"AddType application/x-font-woff .woff\n" .
		"AddType application/x-font-woff2 .woff2\n" .
		"AddType application/x-font-opentype .otf\n" .
		"AddType application/vnd.ms-fontobject .eot\n" .
		"</IfModule>\n" .
		"# プロクシキャッシュの設定（画像とフォントをキャッシュ）\n" .
		"<IfModule mod_headers.c>\n" .
		"<FilesMatch \"\\.(ico|jpe?g|png|gif|svg|swf|pdf|ttf|woff|woff2|otf|eot)$\">\n" .
		"Header set Cache-Control \"max-age=604800, public\"\n" .
		"</FilesMatch>\n" .
		"Header append Vary Accept-Encoding env=!dont-vary\n" .
		"</IfModule>\n" .
		"# ブラウザキャッシュの設定\n" .
		"<IfModule mod_headers.c>\n" .
		"<ifModule mod_expires.c>\n" .
		"ExpiresActive On\n" .
		"# キャッシュ初期化（1秒に設定）\n" .
		"ExpiresDefault \"access plus 1 seconds\"\n" .
		"# MIME Type ごとの設定\n" .
		"ExpiresByType text/css \"access plus  1 year\"\n" .
		"ExpiresByType text/js \"access plus  1 year\"\n" .
		"ExpiresByType text/javascript \"access plus  1 year\"\n" .
		"ExpiresByType image/gif \"access plus  1 year\"\n" .
		"ExpiresByType image/jpeg \"access plus  1 year\"\n" .
		"ExpiresByType image/png \"access plus  1 year\"\n" .
		"ExpiresByType image/svg+xml \"access plus 1 year\"\n" .
		"ExpiresByType image/webp \"access plus  1 year\"\n" .
		"ExpiresByType application/pdf \"access plus  1 year\"\n" .
		"ExpiresByType application/javascript \"access plus  1 year\"\n" .
		"ExpiresByType application/x-javascript \"access plus  1 year\"\n" .
		"ExpiresByType application/x-shockwave-flash \"access plus 1 year\"\n" .
		"ExpiresByType application/x-font-ttf \"access plus 1 year\"\n" .
		"ExpiresByType application/x-font-woff \"access plus 1 year\"\n" .
		"ExpiresByType application/x-font-woff2 \"access plus 1 year\"\n" .
		"ExpiresByType application/x-font-opentype \"access plus 1 year\"\n" .
		"ExpiresByType application/vnd.ms-fontobject \"access plus 1 year\"\n" .
		"</ifModule>\n" .
		"</IfModule>\n" .
		"# Gzip圧縮の設定\n" .
		"<IfModule mod_deflate.c>\n" .
		"SetOutputFilter DEFLATE\n" .
		"# 古いブラウザでは無効\n" .
		"BrowserMatch ^Mozilla/4\\.0[678] no-gzip\n" .
		"BrowserMatch ^Mozilla/4 gzip-only-text/html\n" .
		"BrowserMatch \\bMSIE\\s(7|8) !no-gzip !gzip-only-text/html\n" .
		"# 画像など圧縮済みのコンテンツは再圧縮しない\n" .
		"SetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png|webp|ico|eot|woff|woff2)$ no-gzip dont-vary\n" .
		"AddOutputFilterByType DEFLATE text/plain\n" .
		"AddOutputFilterByType DEFLATE text/html\n" .
		"AddOutputFilterByType DEFLATE text/xml\n" .
		"AddOutputFilterByType DEFLATE text/css\n" .
		"AddOutputFilterByType DEFLATE text/js\n" .
		"AddOutputFilterByType DEFLATE image/svg+xml\n" .
		"AddOutputFilterByType DEFLATE application/xml\n" .
		"AddOutputFilterByType DEFLATE application/xhtml+xml\n" .
		"AddOutputFilterByType DEFLATE application/rss+xml\n" .
		"AddOutputFilterByType DEFLATE application/atom_xml\n" .
		"AddOutputFilterByType DEFLATE application/javascript\n" .
		"AddOutputFilterByType DEFLATE application/x-javascript\n" .
		"AddOutputFilterByType DEFLATE application/x-httpd-php\n" .
		"AddOutputFilterByType DEFLATE application/x-font-ttf\n" .
		"AddOutputFilterByType DEFLATE application/x-font-opentype\n" .
		"</IfModule>\n";

	return $rules . $content;
}
add_filter('mod_rewrite_rules', 'haup_site_optimize_code_add_to_htaccess');
