.htaccess Redirect GeneratorDeveloper Tools
Generates .htaccess redirect rules for pages, HTTPS, www, and domain moves.
A moved page needs one permanent redirect to its new address, and one typo in .htaccess can take the whole site down with a 500 error. Build the rules, validate the file, and keep a fallback for hosts without Apache.
Apache reads .htaccess on every request to that folder. When it meets a directive it does not understand or that is not allowed there, it stops and returns a 500 Internal Server Error. A misspelled directive, a missing module, or a block that is never closed is enough. The server's error log names the exact line, but by then visitors are already seeing the error page.
A rule that works can still be slow. A redirect chain is several redirects in a row, such as http to https, then www to non-www, then the old page to the new one. Each hop adds delay, and search engines may stop following a long chain. The code matters too:
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently | A page or site has moved for good. Search engines move rankings to the new URL. |
| 302 | Found (temporary) | The move is temporary, such as a sale page or maintenance. |
| 307 | Temporary redirect | Like 302, but a POST stays a POST. |
| 308 | Permanent redirect | Like 301, but the method and body are kept. |
Browsers cache a 301, so a wrong permanent redirect can keep firing on your own machine after you fix the file. Behind a CDN that ends HTTPS, such as Cloudflare in Flexible mode, a rule that checks %{HTTPS} always sees it as off and loops.
Write the rules in the .htaccess Redirect Generator. Enter your domain and the redirect type, then tick the site-wide rules you need: Force HTTPS, www or non-www, Trailing slash, or Move to new domain. Add one row under Page redirects for each old URL. Every rule uses mod_rewrite and starts with RewriteEngine On. Page redirects come first. The old path becomes an anchored pattern with special characters escaped, and /? also catches the same path with a trailing slash. A relative target is turned into a full URL on your preferred host, so the visitor lands on the final address in one step. HTTPS and www are joined in one rule with [OR] conditions:
RewriteEngine On
# Page redirects
RewriteRule ^old-page\.html/?$ https://example.com/new-page [R=301,L]
# HTTPS and non-www in one redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]Paste the result near the top of the .htaccess file in the document root, above any block your CMS already has, such as the WordPress one.
Before you upload, paste the whole file into the .htaccess Validator. It reads the file line by line the way Apache does and lists errors and warnings with line numbers. It compares each directive with the ones allowed in .htaccess and suggests a fix for a close misspelling, such as RewriteCondtion. It checks that blocks like <IfModule> are closed in the right order, and it marks <Directory> and <VirtualHost> as errors because Apache refuses them there. It checks RewriteRule and RewriteCond flags, compiles each pattern to catch unbalanced brackets, and range-checks Redirect and ErrorDocument codes. The file is checked in your browser. The validator checks syntax only. It cannot test what a rule does to a real URL or know which modules your server loads.
Some hosts give you no server config at all, such as GitHub Pages or a plain file host. There, use the Meta Redirect Generator. Enter the target URL and a delay in seconds, and it builds a page with a meta refresh tag, a location.replace() fallback that keeps the old page out of the Back button history, a canonical link to the new URL, noindex, and a visible link. Only http and https targets are accepted. Google treats a 0-second meta refresh as a permanent redirect and a delayed one may be treated as temporary. A server 301 is still the better choice when you can set one.
.htaccess, above the CMS block, and run the whole file through the .htaccess Validator..htaccess, upload a page from the Meta Redirect Generator with a delay of 0 in place of the old page.mod_rewrite and AllowOverride enabled. Nginx, IIS, and most Node hosts ignore .htaccess.RewriteCond %{QUERY_STRING} line.AllowOverride forbids a directive. A meta refresh is a fallback, not an equal of a server 301.Apache stops at any directive it does not understand or that is not allowed there. A typo, a missing module, or an unclosed block are the usual causes. The server error log names the line.
Use 301 when the move is permanent. It tells search engines to index the new URL. Use 302 only for a temporary move.
No. Nginx, IIS, and most Node hosts ignore .htaccess. The redirect has to go in that server's own config.
Browsers cache 301 redirects. Clear the browser cache or test in a private window after each change.
Tools used in this guide
Generates .htaccess redirect rules for pages, HTTPS, www, and domain moves.
Checks .htaccess files for unknown directives, unclosed blocks, and bad rewrite rules.
Builds a meta refresh redirect page with a JavaScript fallback and a visible link.