How to use .htaccess Redirect Generator
The .htaccess Redirect Generator builds Apache mod_rewrite rules for 301 permanent redirects, 302 temporary redirects, HTTPS forcing, www/non-www normalisation, and custom RewriteRule blocks — without requiring knowledge of regex-heavy mod_rewrite syntax. Generated snippets are production-ready and can be copied directly into your server's .htaccess file. All generation happens client-side.
- Choose the redirect type from the menu: 301 (Permanent), 302 (Temporary), force HTTPS, or force www/non-www.
- Enter the source path or pattern (e.g. /old-page) and the destination URL (e.g. /new-page or https://example.com/new).
- Add multiple rules by clicking "Add another redirect" — the tool combines them into a single .htaccess block.
- Enable the RewriteEngine On directive if it is not already in your .htaccess file.
- Copy the generated block and paste it at the top of your .htaccess file, above any existing rules.
- Test the redirect using curl -I or your browser's Network panel before deploying to production.
Your data never leaves your device — 100% private processing.
Understanding mod_rewrite directives
Apache mod_rewrite rewrites URLs using the RewriteEngine, RewriteCond, and RewriteRule directives. RewriteEngine On activates the module. RewriteCond sets a condition that must be true before the following rule is applied — typically used to check SERVER_NAME, HTTPS status, or query strings using regex. RewriteRule takes a regex pattern to match the requested path and a substitution target, followed by flags in square brackets: [R=301,L] issues a 301 redirect and stops processing further rules; [L] alone just rewrites internally without a redirect. The NC flag makes matching case-insensitive.
| Goal | Directive skeleton | Flags |
|---|---|---|
| Force HTTPS | RewriteCond %{HTTPS} off\nRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | R=301, L |
| Force www | RewriteCond %{HTTP_HOST} !^www\.\nRewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | R=301, L |
| Remove www | RewriteCond %{HTTP_HOST} ^www\.(.+)$\nRewriteRule ^ https://%1%{REQUEST_URI} [R=301,L] | R=301, L |
| 301 redirect one page | RewriteRule ^old-slug/?$ /new-slug [R=301,L] | R=301, L |
| 302 temporary redirect | RewriteRule ^promo/?$ /sale [R=302,L] | R=302, L |
301 vs 302 redirects and SEO impact
A 301 redirect signals that the resource has moved permanently, instructing browsers and search engines to update their cached URL and transfer link equity (PageRank) to the destination. Use 301 for all permanent URL changes: domain migrations, slug updates, and HTTP-to-HTTPS transitions. A 302 redirect means the move is temporary — search engines keep indexing the source URL and link equity is not transferred. Incorrect use of 302 for permanent moves is a common SEO mistake that can split link equity across both URLs. Always verify redirects with curl -I to confirm the correct status code is returned.
Worked examples
Force HTTPS
Inputs: redirect type: force HTTPS
Result: RewriteCond %{HTTPS} off → RewriteRule … [R=301,L]
301 page redirect
Inputs: /old-page → /new-page
Result: RewriteRule ^old-page/?$ /new-page [R=301,L]
Remove www
Inputs: canonicalise to non-www
Result: RewriteCond %{HTTP_HOST} ^www\. → [R=301,L]
Glossary
- .htaccess
- A directory-level Apache configuration file that allows per-directory settings without editing the main server config.
- mod_rewrite
- An Apache module that rewrites URLs using regular expressions and conditional logic.
- RewriteRule
- The core mod_rewrite directive that matches a URL pattern and specifies a substitution target and flags.
- 301 redirect
- An HTTP response indicating permanent relocation; browsers cache the destination and search engines transfer link equity.
- RewriteCond
- A condition directive that must evaluate to true before the next RewriteRule is applied.
Related reading
Frequently Asked Questions
Why use .htaccess Redirect Generator?
- Generate mod_rewrite rules for HTTPS forcing, www normalisation, and 301 redirects
- Produce correct RewriteRule syntax with [R=301,L] flags without memorising the directives
- Chain multiple redirect rules into a single .htaccess block in the correct order
- Distinguish 301 permanent vs 302 temporary redirects with guidance on which to use
Common use cases
- Force all HTTP traffic to HTTPS after adding an SSL certificate to an Apache server
- Redirect a renamed blog post slug with a 301 to preserve its accumulated inbound link equity
- Canonicalise all www. traffic to the non-www domain on a newly launched website
- Create a temporary 302 redirect pointing a product page to a sale landing page
- Generate a redirect rule for a full domain migration from one domain to another
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Related Developer Tools
robots.txt Generator
Generate a robots.txt file for your website. Set user-agents, allow/disallow rules, crawl-delay, and sitemap URL. Free, private robots.txt builder.
.gitignore Generator
Generate a .gitignore file for your project. Pick languages, frameworks, and tools to build a ready-to-use git ignore file. Free and private.
URL Encoder / Decoder
Encode and decode URLs and URL components online. Convert special characters to percent-encoding and back instantly — free, private, and fast.
cURL Converter
Convert a curl command to JavaScript fetch, Node, Python requests, or PHP. Paste your curl and get clean client code instantly. Free and private.
Cron Expression Generator
Build and decode cron expressions online. Get a plain-English description of any crontab schedule and a field-by-field breakdown. Free cron generator.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
Explore all Developer Tools.