Skip to content
cosmodev ~/tools/htaccess-generator

.htaccess 重定向生成器

Generators

通过简易编辑器生成 Apache .htaccess 重定向规则:支持按路径设置 301、302 或 308 重定向,并附带强制 HTTPS 与 www 规范化区块。在本地运行,并提供可分享的链接。

重定向规则
服务器规则
强制 HTTPS
规范主机

(文档为英文)

What it does

Builds an Apache .htaccess file from a simple editor instead of hand-written directives. Each rule is a from-path, a target and a status code — 301 permanent, 302 found, or 308 permanent preserving the method. On top of the redirects you can add a force-HTTPS block and www canonicalization (either direction) with their RewriteCond/RewriteRule pairs. Input is validated as you type: paths must start with / and contain no spaces, duplicate from-paths, conflicting canonical directions and protocols in the domain are all named errors. Everything runs locally in your browser.

How to use it

  1. Fill redirect rows under Redirect rules: a source path like /old-blog, a target like /blog or a full URL, and a status code. Add rule appends a row, the × removes one. Sample loads two example rules.
  2. Under Server rules, flip Force HTTPS and/or a www → apex / apex → www direction. Picking a canonical direction reveals the domain field (a bare host, like example.dev).
  3. The generated file appears live on the right, sections ordered: HTTPS first, canonicalization second, redirects last.
  4. Copy takes the file; Download saves it as .htaccess.
  5. Copy share link encodes the whole configuration in the URL.

Examples

One redirect:

Redirect 301 /old-blog /blog

Force HTTPS plus www→apex on example.dev produces an <IfModule mod_rewrite.c> block with RewriteEngine On, a %{HTTPS} off condition redirecting to https://%{HTTP_HOST}…, and a ^www\.example\.dev$ condition redirecting to the apex — dots escaped so the pattern cannot match lookalikes.

Validation example: a second rule with the same from-path reports Duplicate "from" path: /old-blog; https://example.dev in the domain field reports that the protocol must be removed.

Which status code to pick

Code Meaning Use when
301 Moved Permanently the move is forever — search engines transfer ranking
302 Found (temporary) the move may be undone — ranking stays with the old URL
308 Permanent Redirect like 301, but POST stays POST (no method rewrite to GET)

The canonical blocks always emit 301. Place the file in your site root; Apache picks it up per-directory — and because the blocks are wrapped in <IfModule mod_rewrite.c>, a host without mod_rewrite skips them instead of erroring.

源代码14 种语言

100% 客户端运行 · 你的数据永远不会离开浏览器。 觉得好用?分享给同事吧。