#<Files ~ "\.(css|js)$">
#    FileETag MTime Size
#    ExpiresActive On
#    ExpiresDefault "access plus 3 hours"
#    SetOutputFilter DEFLATE
#</Files>
#<Files ~ "\.(gif|jpeg|jpg|png|flv|mp4|ico|svg)$">
#    FileETag None
#    ExpiresActive On
#    ExpiresDefault "access plus 14 days"
#</Files>

# ログインページをIPアドレス制限
# SetEnvIf Request_URI "(/login/)" login
# Order Deny,Allow
# Deny from env=login
# Allow from IP xxx.xxx.xxx.xxx

# セキュリティ周りのヘッダー
# Header set X-Frame-Options SAMEORIGIN
# Header set X-Content-Type-Options 'nosniff'
# Header set X-XSS-Protection '1; mode=block'
# Header set Strict-Transport-Security 'max-age=315360000'

# php 設定
# php_value max_input_vars 99999
# php_value memory_limit 512M
# php_value post_max_size 64M
# php_value upload_max_filesize 16M

RewriteEngine on

# RewriteBase /

# basic auth 対応
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# webpフォーマット画像対応
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} (.*)\.(jpe?g|png)$
RewriteCond %{REQUEST_FILENAME}\.webp -f
RewriteCond %{QUERY_STRING} !type=original
RewriteRule (.+)\.(jpe?g|png)$ %{REQUEST_FILENAME}.webp [T=image/webp,E=accept:1]
<IfModule mod_headers.c>
    Header append Vary Accept env=REDIRECT_accept
</IfModule>
<IfModule mod_mime.c>
    AddType image/webp .webp
</IfModule>

# wwwあり、なし正規化
# RewriteCond %{HTTP_HOST} ^(example\.com)(:80)?
# RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NE,L]

# 存在するファイルへの直指定の場合、CMSを通さない
# RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

# index.html なしへの正規化
RewriteRule ^(.*)/index.html$ http://%{HTTP_HOST}/$1/ [R=301,NE,L]
RewriteRule ^index.html$ http://%{HTTP_HOST}/ [R=301,NE,L]

# 最後にスラッシュをつける
RewriteCond %{REQUEST_URI} (.*(^|/)[^\./]+)$
RewriteRule .* %1/ [L,NE,R=301]

# 拡張子がある場合、最後のスラッシュをとる
RewriteCond %{REQUEST_METHOD} ^(GET)$
RewriteCond %{REQUEST_URI} (.*\.[^/\.]+)/$
RewriteRule .* %1 [L,NE,R=301]

# メンテナンスモード時に503ページを出力 (setup_は環境に合わせて変更して下さい)
# RewriteRule ^setup_/ - [L]
# RewriteRule ^(.*)$ setup_/503.php [L]

# a-blog cms以外のコンテンツ（a-blog cmsを動作させないコンテンツ）
# RewriteCond %{REQUEST_URI} !^/?other/
# RewriteCond %{REQUEST_URI} !^/?other2/
RewriteCond %{REQUEST_URI} !/js/locales/(.*)/translation.json

# CMSを実行
RewriteRule ((\.(html|htm|php|xml|txt|js|json|css|yaml|csv))|/)$ index.php [L]
