htaccess Redirect Generator

Build the redirect block, copy it, and check one URL before you upload it.

No www and no https://. Used by the HTTPS and host rules.

Starts with /, such as /old-page.

A path or a full https:// address.

Matches “Page redirect” and goes to https://example.com/new-page.

More rules: slash, extension, domain move, bulk

One pair per line. A comma or a tab between the old path and the new URL.

Which snippet to show
RewriteEngine On

# Page redirects. RewriteRule keeps these in the same pass as the rules below.
RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]

# Force HTTPS and drop www, in one redirect.
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

How to use this htaccess redirect generator

  1. Enter the domain. Force HTTPS and Non-www are already on, which is the usual permanent setup.
  2. Add one old path and its new URL, or open More rules and paste a list.
  3. Read the warnings. A loop points a URL at itself. A chain points at another URL that also moves.
  4. Use Test a URL, then copy the Apache block or download the .htaccess file. The Nginx tab is the same plan for Nginx.

Redirect HTTP to HTTPS in htaccess

The HTTPS rule checks that the request is still plain HTTP, then sends the same path to https. When Non-www or www is selected, the host changes in that same redirect. A visitor who typed http://www.example.com/about lands on https://example.com/about once, not twice.

www to non-www htaccess

Choose Non-www and the file matches only www.yourdomain.com. The bare domain is left alone, so the rule cannot loop. Choose www if the preferred host is the one with www. Leave the host alone when another service already picks the host.

Redirect cheat sheet

This 301 redirect generator uses Redirect for a lone path rule. It switches to RewriteRule as soon as a condition is needed. That is also what you want from an htaccess generator when several rules share one file.

Lines you will see in the file
LineWhat it does
Redirect 301 /old https://example.com/newOne permanent path change
RewriteCond %{HTTPS} !=onOnly when the request is still HTTP
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]Send the same path to HTTPS
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]Match the www host
[R=301,L]Permanent redirect, then stop
[R=302,L]Temporary redirect, then stop

FAQ

What does this htaccess redirect generator make?

It writes the lines you paste into an .htaccess file. A single old path can point at a new URL, or you can paste many pairs. HTTPS, www, trailing slashes, file extensions, and a domain move can be added to the same file. The rules run in the browser and nothing you type is uploaded.

When should I use a 301 redirect generator instead of 302?

Use 301 when the move is permanent. Search engines treat a 301 as the new address. Use 302 only when the new address is temporary, such as a short campaign. This page defaults to 301.

How do I redirect HTTP to HTTPS in htaccess?

Turn on Force HTTPS and enter your domain. The file checks that the request is not already HTTPS, then sends it to https on the preferred host. If www is also selected, both changes happen in one redirect so visitors are not sent twice.

How do I redirect www to non-www in htaccess?

Choose Non-www as the host. Requests to www.yourdomain.com are sent to the bare domain. Choose www if you want the opposite. The host is checked so a request that is already correct is left alone.

Why does a simple path use Redirect 301, but HTTPS uses RewriteRule?

Redirect 301 is enough for one path on the same site, and it is easy to read. HTTPS, www, trailing slashes, and extension hiding need conditions, so those use RewriteEngine. When those are on, the path rules are RewriteRule lines too, because mixing Redirect and RewriteRule in one file can run in a surprising order.

What is a redirect loop or a chain?

A loop sends a URL back to itself. A chain sends it to a second URL that is also redirected. The page warns about both. The test box under the rules tells you which rule matches a URL you type, and whether that result would be redirected again.

Will this htaccess generator work on Hostinger?

Yes. Hostinger shared hosting uses Apache or LiteSpeed, and both read .htaccess. Upload the file to the site folder, or merge these lines into the file that is already there. Back up the current file first. Nginx hosting does not read .htaccess, so use the Nginx tab on those servers.

More from CoreCodify

This generator is free. CoreCodify also sells kits for moving a site and checking it before launch. Checkout stays on Gumroad.