S SEO ProCheck Tools seoprocheck.com →
← All tools

Htaccess Redirect Generator

Build .htaccess 301/302 redirect rules.

Htaccess Redirect Generator

What it does

This generator writes Apache .htaccess redirect rules for seven common jobs: a single 301 or 302 redirect, forcing HTTPS, adding or removing www, and adding or removing a trailing slash. The 301 and 302 options produce a one line Redirect directive from mod_alias. The other five produce a small mod_rewrite block that starts with RewriteEngine On and sends a 301. The tool does not test anything against your server; it prints text for you to paste.

How to use it

  1. Choose the rule in Redirect Type. The URL fields only show for the 301 and 302 options.
  2. For a single redirect, enter the Old URL Path as a path that starts with a slash, such as /old-page/, and the New URL as a full address.
  3. Click Generate Code, then Copy.
  4. Download a backup of your current .htaccess, paste the rule in, and test the old URL in a browser or with a header checker.

How Apache will read these rules

A Redirect line matches the old path as a prefix, on whole path segments. Redirect 301 /blog /news also sends /blog/post-1 to /news/post-1, and query strings carry over. That is often what you want in a migration, but not if you meant one page only. The old path is case sensitive and must not include the domain; a full URL there will never match.

The Force WWW and Remove WWW rules always redirect to https://, so use them only on a site that already has a working certificate. If you stack either of them with Force HTTPS, put the www rule first; in the other order, a visit to http://example.com can take two hops. Apache also does not promise to run mod_alias and mod_rewrite lines in the order they appear, so test when you mix them. A syntax error in .htaccess usually returns a 500 error for every URL the file covers, and Nginx ignores .htaccess entirely.