.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生成器
为样机和设计稿生成占位文本。可选择段落、句子或单词。