Skip to content
cosmodev ~/tools/htaccess-generator

Trình tạo chuyển hướng .htaccess

Generators

Tạo quy tắc chuyển hướng Apache .htaccess từ một trình chỉnh sửa đơn giản: chuyển hướng theo từng đường dẫn với 301, 302 hoặc 308, cùng các khối buộc HTTPS và chuẩn hóa www. Chạy cục bộ với liên kết chia sẻ được.

Quy tắc chuyển hướng
Quy tắc máy chủ
Buộc dùng HTTPS
Máy chủ canonical

(Tài liệu bằng tiếng Anh)

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.

Mã nguồn14 ngôn ngữ

100% phía client · dữ liệu của bạn không bao giờ rời khỏi trình duyệt. Thấy hữu ích? Chia sẻ với đồng nghiệp của bạn.