Skip to main content
ToolsHub

.htaccess Redirect Generator

Build Apache .htaccess rules without memorizing mod_rewrite syntax — 301/302 redirects, force HTTPS, and www normalization. Copy the generated block straight into your server config.

Updated

Files never leave your browser

Custom redirects

Generated .htaccess

RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]

# Custom redirects
Redirect 301 /old-page /new-page

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.

  1. Choose the redirect type from the menu: 301 (Permanent), 302 (Temporary), force HTTPS, or force www/non-www.
  2. Enter the source path or pattern (e.g. /old-page) and the destination URL (e.g. /new-page or https://example.com/new).
  3. Add multiple rules by clicking "Add another redirect" — the tool combines them into a single .htaccess block.
  4. Enable the RewriteEngine On directive if it is not already in your .htaccess file.
  5. Copy the generated block and paste it at the top of your .htaccess file, above any existing rules.
  6. 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.

Common .htaccess redirect patterns
GoalDirective skeletonFlags
Force HTTPSRewriteCond %{HTTPS} off\nRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]R=301, L
Force wwwRewriteCond %{HTTP_HOST} !^www\.\nRewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]R=301, L
Remove wwwRewriteCond %{HTTP_HOST} ^www\.(.+)$\nRewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]R=301, L
301 redirect one pageRewriteRule ^old-slug/?$ /new-slug [R=301,L]R=301, L
302 temporary redirectRewriteRule ^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

Free · No spam

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

Explore all Developer Tools.