#suPHP_ConfigPath /home/n-kurarisu/thereracs.net/xserver_php/
# wwwありをなしに統一
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.thereracs.net$
    RewriteRule (.*) https://thereracs.net/$1 [R=301,L]
</IfModule>
# HTTPをHTTPSにリダイレクト
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# 旧商品リストのリダイレクト
<IfModule mod_rewrite.c>
    RewriteEngine on
    RedirectMatch 301 ^/products/list\.php https://thereracs.net/?
</IfModule>
# MIME設定
AddType video/mp4 .mp4
AddType video/ogg .ogv
AddType video/webm .webm
AddType image/svg+xml .svg
AddType image/svg+xml .svgz
# --- ここから末尾の共通設定 ---
DirectoryIndex index.php index.html .ht
<Files ~ "/index.php">
    order deny,allow
    allow from all
</Files>
# 重要なファイルやディレクトリへのアクセス制限
<FilesMatch "(?<!\.gif|\.png|\.jpg|\.jpeg|\.css|\.ico|\.js|\.svg|\.map)$">
    SetEnvIf Request_URI "/vendor/" deny_dir
    Order allow,deny
    Deny from env=deny_dir
    Allow from all
</FilesMatch>
<FilesMatch "^composer|^COPYING|^\.env|^\.maintenance|^Procfile|^app\.json|^gulpfile\.js|^package\.json|^package-lock\.json|web\.config|^Dockerfile|^\.editorconfig|\.(ini|lock|dist|git|sh|bak|swp|env|twig|yml|yaml|dockerignore|sample)$">
    order allow,deny
    deny from all
</FilesMatch>
<IfModule mod_setenvif.c>
    SetEnvIf Request_URI "\.(jpe?g|png)$" _image_request
</IfModule>
<IfModule mod_headers.c>
    # クリックジャッキング対策
    Header always set X-Frame-Options SAMEORIGIN
    # XSS対策
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Content-Type-Options nosniff
    # --- 追加対策 ---
    # HSTS設定 (Strict-Transport-Security): 黄色アラート対策
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    # CSP設定 (Content-Security-Policy): オレンジアラート対策
    Header set Content-Security-Policy "default-src 'self' https: 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: https: blob:; font-src 'self' data: https:; frame-src 'self' https:;"
    # -------------------------
    # webp対応
    Header append Vary Accept env=_image_request
</IfModule>
# PHP設定
# デザインテンプレートを適用するため10Mで設定
<IfModule mod_php7.c>
    php_value post_max_size 10M
    php_value upload_max_filesize 10M
</IfModule>
<IfModule mod_php.c>
    php_value post_max_size 10M
    php_value upload_max_filesize 10M
</IfModule>
<IfModule mod_rewrite.c>
#403 Forbidden対応方法
#ページアクセスできない時シンボリックリンクが有効になっていない可能性あります、
#オプションを追加してください
#Options +FollowSymLinks +SymLinksIfOwnerMatch
    RewriteEngine On
    # webpルーティング
    # Acceptヘッダがimage/webpを含む場合
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{SCRIPT_FILENAME}.webp -f
    RewriteRule .(jpe?g|png)$ %{SCRIPT_FILENAME}.webp [T=image/webp]
    # リダイレクト設定
    #商品詳細ページ向けリダイレクト
    RewriteCond %{QUERY_STRING} ^product_id=(.*)$
    RewriteRule ^products/detail\.php$ https://thereracs.net/products/detail/%1? [R=302,L]
    #カテゴリリダイレクト
    RewriteCond %{QUERY_STRING} ^category_id=(.*)$
    RewriteRule ^products/shop\.php$ https://thereracs.net/products/shop/ [R=302,L]
    RewriteRule ^user_data/COLLECTION_2024ss.php$ https://thereracs.net/user_data/COLLECTION_2024SS? [R=302,L]
    # Authorizationヘッダ対応
    # Authorization ヘッダが取得できない環境への対応
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
    # セキュリティ: 特定フォルダへのアクセス拒禁止
    RewriteRule "^\.git" - [F]
    RewriteRule "^src/" - [F]
    RewriteRule "^app/" - [F]
    RewriteRule "^tests/" - [F]
    RewriteRule "^var/" - [F]
    RewriteRule "^vendor/" - [F]
    RewriteRule "^node_modules/" - [F]
    RewriteRule "^gulp/" - [F]
    RewriteRule "^codeception/" - [F]
    RewriteRule "^bin/" - [F]
    RewriteRule "^dockerbuild/" - [F]
    RewriteRule "^\.devcontainer/" - [F]
    RewriteRule "^zap/" - [F]
    # EC-CUBE フロントエンドコントローラーへのルーティング
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !^(.*)\.(gif|png|jpe?g|css|ico|js|svg|map)$ [NC]
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_mime.c>
    # 拡張子.webpファイルはContent-Typeとしてimage/webpを返す
    AddType image/webp .webp
</IfModule>
SetEnvIf Request_URI ".*" Ngx_Cache_NoCacheMode=off
SetEnvIf Request_URI ".*" Ngx_Cache_AllCacheMode
