Htaccess Redirect Generator

Generate .htaccess rules for www, HTTPS and 301 page redirects.

Runs instantly in your browser — results update as you type.

What is an .htaccess redirect?

An .htaccess redirect is a rule in Apache's .htaccess configuration file that sends visitors and search engines from one URL to another, usually with a permanent 301 status. It is used to force HTTPS, unify www and non-www versions, and move individual pages.

How to use the Htaccess Redirect Generator

    Frequently asked questions

    How do I redirect HTTP to HTTPS in .htaccess?

    Add RewriteEngine On, then RewriteCond %{HTTPS} off and RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]. The generator writes this for you.

    Should I use www or non-www?

    Either works for SEO. Pick one, redirect the other with a 301, and use the same version in canonicals, sitemaps and Search Console.

    Why does my redirect cause a loop?

    Usually a proxy or CDN is sending HTTP traffic to Apache, so the HTTPS rule fires every time. Check X-Forwarded-Proto instead of %{HTTPS}, or redirect at the CDN.

    What is the difference between Redirect 301 and RewriteRule?

    Redirect 301 (mod_alias) is simple and good for single pages. RewriteRule (mod_rewrite) supports conditions and patterns, which you need for HTTPS and www rules.

    Does .htaccess work on nginx?

    No. nginx does not read .htaccess files; use a return 301 or rewrite directive in the server configuration instead.