.htaccess Redirect Generator
Generate correct Apache .htaccess redirect rules for the most common canonicalization jobs - force HTTPS, www vs non-www, and single-page redirects - with the right 301 or 302 status code.
Generated .htaccess rules
Add these lines near the top of the .htaccess file in your site root (Apache with mod_rewrite enabled).
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]About .htaccess Redirect Generator
The .htaccess Redirect Generator builds ready-to-paste mod_rewrite rules for the redirects that most sites need. Pick a scenario and the tool writes the matching RewriteEngine, RewriteCond, and RewriteRule lines for you: force HTTPS, redirect non-www to www, redirect www to non-www, a combined force HTTPS + www rule, or a redirect from one specific page to another. You also choose the status code - 301 for a permanent move that passes SEO signals to the new address, or 302 for a temporary redirect that tells search engines the change is not permanent.
The generated rules follow Apache conventions correctly rather than approximately. Host names are matched with a case-insensitive [NC] flag and their dots are escaped so they are treated literally in the regular expression, path and query are preserved through the $1 backreference, and each rule ends with the [L] flag to stop further rewriting once it matches. The HTTPS rule keys off %{HTTPS} off and reuses %{HTTP_HOST} so it works on any domain without hard-coding it, while the www rules build the target from the domain you enter.
Everything is generated in your browser as you change the options - no domain, path, or destination you type is uploaded anywhere. Copy the output into the .htaccess file at your site root (on Apache with mod_rewrite enabled), near the top so the redirect runs before other rules. Getting canonical redirects right matters for SEO and security: it collapses duplicate versions of your site onto one canonical address, avoids splitting link signals across http/https and www/non-www variants, and makes sure every visitor lands on the encrypted, preferred URL.
How to use it
- 1Choose a redirect scenario: force HTTPS, non-www to www, www to non-www, force HTTPS + www combined, or redirect a single page.
- 2Select the redirect type - 301 permanent (passes SEO signals) or 302 temporary.
- 3Enter your domain if the scenario needs it, and for a single-page redirect add the old path and the destination URL.
- 4Copy the generated rules from the output block.
- 5Paste them near the top of the .htaccess file in your site's root directory on an Apache server with mod_rewrite enabled.
Common use cases
- -Forcing every visitor onto HTTPS after installing an SSL certificate, so no one lands on the insecure http:// version.
- -Choosing one canonical hostname by redirecting www to non-www (or the reverse) to avoid duplicate-content splits.
- -Redirecting an old or retired page to its replacement with a proper 301 so rankings and links carry over.
- -Combining the HTTPS and www redirects into a single rule so both are enforced together on a new site launch.
- -Standardizing redirects across multiple sites without memorizing mod_rewrite regex syntax by hand.
Frequently asked questions
- What is the difference between a 301 and a 302 redirect?
- A 301 is a permanent redirect that tells search engines the move is final and passes ranking signals to the new URL. A 302 is temporary and signals that the original URL will return, so search engines keep indexing it. Use 301 for permanent canonicalization.
- Where do I put the generated .htaccess rules?
- Paste them near the top of the .htaccess file in your website's root directory, on an Apache server with mod_rewrite enabled. Placing them early ensures the redirect runs before other rewrite rules process the request.
- How do I force HTTPS in .htaccess?
- Use a rule that checks RewriteCond %{HTTPS} off and rewrites the request to https://%{HTTP_HOST}/$1 with a 301 flag. This generator produces that rule for you and reuses %{HTTP_HOST}, so it works on any domain without editing.
- How do I redirect www to non-www (or non-www to www)?
- Add a RewriteCond that matches the unwanted hostname, then a RewriteRule that sends traffic to the preferred one with a 301. Select the matching scenario, enter your domain, and the tool writes the correct condition with the dots escaped.
- Does this tool send my domain or URLs anywhere?
- No. The .htaccess Redirect Generator runs entirely in your browser. The domain, paths, and destinations you enter are used only to build the rules locally and are never uploaded to any server.
- Will these redirects preserve the rest of the URL path?
- Yes. The generated rules capture the requested path with (.*) and append it to the destination through the $1 backreference, so a visitor to a deep page is redirected to the same page on the canonical URL, not just the homepage.