跳至主要內容
kitlocal.dev

.htaccess 產生器

本機執行

100% 在你的瀏覽器中處理。輸入與輸出絕不會離開你的裝置。

產生 Apache .htaccess 規則,涵蓋重新導向、改寫與安全性。

Apache 規則

將重新導向、快取與 SPA 路由規則整合至可下載的 .htaccess 檔案中。

快速設定

需要 Apache 2.4、對應模組與 AllowOverride 權限,請先於測試環境驗證。若位於終止 TLS 的代理伺服器後方,請先在伺服器上設定受信任的 HTTPS 偵測機制。

標準化重新導向會指向上述固定網域。停用「強制使用 HTTPS」時,將保留目前的 HTTP 或 HTTPS 協定。永久重新導向可能會被瀏覽器快取。

.htaccess

# Generated by KitLocal — Apache 2.4; AllowOverride must permit these directives.

RewriteEngine On

# Canonical redirect (fixed host avoids trusting HTTP_HOST).
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json application/javascript image/svg+xml
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
26 行893 位元組.htaccess