在线免费.htaccess生成器
为重定向、缓存和安全性生成.htaccess规则。
Who uses the .htaccess生成器?
- 无需插件开销、为迁移后的网址添加重定向规则的 WordPress 网站所有者。
- 在 Apache 主机上强制实施 HTTPS 及 www/非 www 一致性的 Web 开发者。
- 为新的 Apache 部署快速生成缓存和 gzip 规则的网站所有者。
How the .htaccess生成器 works
勾选你需要的规则:Force HTTPS、重定向到/取消 www、Gzip、浏览器缓存、自定义 404、禁止目录列表,或 CORS。
如果勾选了自定义 404 选项,请填写对应页面的路径。
添加旧网址→新网址的对应关系(每行一对),用于生成 301 重定向。
复制生成的 .htaccess 内容,上传到服务器的文档根目录。
Tips & tricks
- 不要同时勾选“Redirect to www”和“Remove www”——它们会互相冲突;请为你的域名选择一种规范形式。
- 本工具不会生成 Basic Auth 密码保护——这需要另外创建一个 .htpasswd 文件,以及需要你手动添加的 AuthType 规则。
- 重定向列表要求每行恰好用空格分隔两个值(旧路径、新路径)——不符合此格式的行会被静默忽略。
- 替换现有 .htaccess 之前务必先备份——语法错误可能导致整个网站出现 500 错误。
Frequently Asked Questions
什么是 .htaccess 文件?
.htaccess(hypertext access)是 Apache Web 服务器在目录级别的配置文件。它让你无需修改主服务器配置就能设置服务器规则:重定向、URL 重写、身份验证、MIME 类型、访问控制等等。
这个工具会生成密码保护(Basic Auth)规则吗?
不会——本生成器涵盖 HTTPS/www 重定向、gzip、缓存、自定义 404、目录列表、CORS 以及简单的 301 重定向。如需密码保护,你需要手动添加 AuthType Basic / AuthUserFile 规则,并另行单独创建一个 .htpasswd 文件。
如何把 www 重定向到非 www(或反过来)?
本工具以复选框的形式生成两种方向——“Redirect to www”和“Remove www”——选择与你偏好的规范域名一致的那个。两者只能启用其中一个。
.htaccess 在 Nginx 或其他 Web 服务器上有效吗?
.htaccess 是 Apache 专用的。Nginx 使用位于 /etc/nginx/sites-available/ 的服务器块配置文件。Cloudflare 使用 Page Rules 或 Workers。本生成器面向 Apache——使用前请先确认你的服务器类型。
一个有问题的 .htaccess 文件会导致网站出错吗?
会。.htaccess 中的语法错误会导致该目录出现 500 Internal Server Error。修改前务必备份现有文件,并先在预发布环境中测试。Apache 的错误日志会显示具体的语法错误位置。
Is my data safe when using the .htaccess生成器?
Completely safe. The .htaccess生成器 processes everything locally in your browser. No input data, results, or usage information is ever transmitted to or stored on any server.
Can I use the .htaccess生成器 output in commercial projects?
Yes. The .htaccess生成器 is a utility tool and its output carries no licensing restrictions. You are free to use results in any project, commercial or personal.
Does the .htaccess生成器 follow official standards?
Yes. The .htaccess生成器 is built to comply with the relevant industry standard or specification for this utility type. If you encounter an unexpected result, verify your input against the specification — edge cases outside the standard may produce undefined behaviour.