Tools

.htaccess Redirect Generator

Apache 301 redirects and HTTPS/www rules for .htaccess

Site-wide rules
.htaccess

    

    How to create .htaccess redirects

    1. List the old paths and their new URLs, one pair per line, separated by a space. Paste two columns from a spreadsheet if you have many.
    2. Choose 301 for permanent moves. Tick Force HTTPS and choose to add or remove www if you also want site-wide rules.
    3. Copy the rules into the .htaccess file in your website's root folder, above any existing CMS rules such as WordPress's # BEGIN WordPress block.
    4. Test old URLs in a private browser window, and check that the new pages load with status 200.

    How the rules work

    The generator uses Apache's mod_rewrite, which is available on nearly all shared hosting. Each redirect becomes a RewriteRule with the [L,R=301] flags: L stops processing further rules and R=301 sends a permanent redirect. Special characters in paths are escaped so dots and brackets match literally. Paths with query strings, such as /shop?id=42, get a RewriteCond %{QUERY_STRING} line, because RewriteRule alone never sees the query string; the trailing ? in the target drops the old query.

    A /folder/* source redirects everything in that folder and keeps the rest of the path with :splat. Rules are processed top to bottom, so site-wide HTTPS and www rules come first. If your server returns a 500 error after editing, check that mod_rewrite is enabled and that the file has no typos. Everything is generated in your browser.

    FAQ

    Why is my .htaccess redirect not working?

    Check that mod_rewrite is enabled, that AllowOverride permits .htaccess files, that rules come before your CMS rules, and clear your browser cache, which stores 301s.

    Should I use Redirect or RewriteRule?

    Simple Redirect 301 lines work for plain paths, but RewriteRule handles query strings, patterns and HTTPS rules, so the generator uses it consistently.

    Can I redirect a whole domain?

    Yes. Put the rules on the old domain with RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301].