現象
gzファイルを準備してあるjsやcssをクライアントが要求したら、
それらのgzファイルを返送したいですが、クライアントには404で返ります。
設定直後は、3つ目のRewriteCondで.css.gzファイルが見つからずに.cssファイルが返っておりましたが
RewriteCondに実ファイルパスを指定することで、ようやくmatchedになりました。
しかし、その後の動作で404となってしまう原因が判りません。
環境
apache バージョンは2.2です。
apache と tomcat8 を組み合わせてアプリを構築しています。
apacheはc:\apache2.2にインストールしています。
.htaccessは使用していません。(存在しません)
c:\apache2.2\conf\httpd.confの記述を抜粋します。
httpd.conf
1ServerRoot "C:/Apache2.2" 2LoadModule rewrite_module modules/mod_rewrite.so 3DocumentRoot "C:/Apache2.2/htdocs" 4<Directory /> 5 Options FollowSymLinks 6 AllowOverride None 7 Order deny,allow 8 Deny from all 9</Directory> 10<Directory "C:/Apache2.2/htdocs"> 11 Options Indexes FollowSymLinks 12 AllowOverride None 13 Order allow,deny 14 Allow from all 15</Directory> 16<IfModule mod_rewrite.c> 17 RewriteEngine on 18 RewriteLog logs/rewrite.log 19 RewriteLogLevel 9 20 RewriteCond %{HTTP:Accept-Encoding} gzip 21 RewriteCond %{REQUEST_URI} (\.js|\.css)$ 22 RewriteCond C:/pleiades4.5/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps%{REQUEST_FILENAME}\.gz -s 23 24> eclipse開発環境用のパスです。 25> 運用環境では、C:/Tomcat8.5/webappsとする予定です。 26 27 RewriteRule .+ %{REQUEST_URI}\.gz 28</IfModule> 29<FilesMatch "\.css\.gz$"> 30 ForceType text/css 31 AddEncoding x-gzip .gz .tgz 32 AddType text/css .gz 33 Header set Content-Encoding gzip 34</FilesMatch> 35<FilesMatch "\.js\.gz$"> 36 ForceType application/x-javascript 37 AddEncoding x-gzip .gz .tgz 38 AddType application/x-javascript .gz 39 Header set Content-Encoding gzip 40</FilesMatch> 41Header append Vary Accept-Encoding env=!dont-vary
上記を実行した場合のrewriteのログは以下のように出力されます。
(3) applying pattern '.+' to uri '/project/js/bootstrap-3.3.6/css/bootstrap.min.css' (4) RewriteCond: input='gzip, deflate' pattern='gzip' => matched (4) RewriteCond: input='/project/js/bootstrap-3.3.6/css/bootstrap.min.css' pattern='(\\.js|\\.css)$' => matched (4) RewriteCond: input='C:/pleiades4.5/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/project/js/bootstrap-3.3.6/css/bootstrap.min.css.gz' pattern='-s' => matched (2) rewrite '/project/js/bootstrap-3.3.6/css/bootstrap.min.css' -> '/project/js/bootstrap-3.3.6/css/bootstrap.min.css.gz' (2) local path result: /project/js/bootstrap-3.3.6/css/bootstrap.min.css.gz (2) prefixed with document_root to C:/Apache2.2/htdocs/project/js/bootstrap-3.3.6/css/bootstrap.min.css.gz (1) go-ahead with C:/Apache2.2/htdocs/project/js/bootstrap-3.3.6/css/bootstrap.min.css.gz [OK]
クライアントに返る応答ヘッダは以下の通りです。
"GET /project/js/bootstrap-3.3.6/css/bootstrap.min.css HTTP/1.1" 404 242
-2016/12/15 追記-
ネットで探し続けていますが、windows版apacheでgzファイルを返す情報が少ないと感じています。
ある場合も、.htaccessだったりします。
こういうhttpd.confで出来たよー。と、実績があるhttpd.confを
見せて頂けたら幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。