.htaccess程式碼片段產生器
產生常見的.htaccess規則:強制HTTPS、重新導向www、設定快取標頭、啟用Gzip。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]如何使用本工具
- 1
Open the dropdown and choose the rule you need (for example, Force HTTPS or Gzip compression).
- 2
Read the generated snippet shown in the code box below the dropdown.
- 3
Select the text and copy it, then paste it into your site's .htaccess file.
- 4
Switch the dropdown to a different rule to view another snippet — combine several by pasting them one after another.
什麼是.htaccess程式碼片段產生器?
.htaccess是Apache的目錄層級設定檔。它控制URL重寫、重新導向、快取、壓縮和安全標頭。Hostinger以及大多數共享主機都使用Apache(或相容的LiteSpeed)。這些程式碼片段涵蓋了最常見的需求。
常見使用場景
Forcing every visitor onto HTTPS after installing an SSL certificate on a shared Apache or LiteSpeed host.
Canonicalizing a domain to either the www or non-www version with a 301 redirect to consolidate SEO signals.
Adding a one-year browser cache to static assets so repeat visitors load CSS, JS, and modern image formats from cache.
Turning on Gzip compression for text responses to cut transfer size and improve page load time.
Hiding the contents of a folder that has no index file by disabling Apache's automatic directory listing.
Blocking PHP execution inside a public uploads directory so an attacker can't run a script they managed to upload.
常見問題
.htaccess在Nginx上能用嗎?▼
我應該把.htaccess放在哪裡?▼
相關工具
密碼產生器
在你的瀏覽器中產生具有加密強度的密碼。不會向任何伺服器傳送任何內容:隨機位元組來自你瀏覽器的crypto API。
WordPress使用者名稱產生工具
產生安全、隨機的WordPress管理員使用者名稱。切勿使用「admin」:它是暴力破解的頭號攻擊目標。
網域名稱產生器
根據一個關鍵字產生具有品牌潛力的網域名稱創意。組合方式包含常見的前綴、後綴和修飾詞。
公司名稱產生器
產生具有品牌潛力的公司名稱創意。將真實詞彙與修飾詞組合,產生易記的名稱。
URL別名(slug)產生工具
將文字轉換為適合URL的別名:轉為小寫、移除特殊字元,並用連字號分隔單字。
Lorem Ipsum 產生器
為樣機和設計稿產生佔位文字。可選擇段落、句子或單字。