.htaccess Redirects Generator: Free Online Tool

.htaccess Redirects

Select a redirect type and configure the settings to generate your .htaccess code.

Redirect between www and non-www versions of your domain. This helps avoid duplicate content issues.

Enter without www or http:// (e.g. yourdomain.com)

Use this free generator to create htaccess redirects for Apache: 301 and 302 page redirects, www and non-www, HTTPS, domain moves, directories and file extensions. Pick a redirect type, fill in a few fields, then copy or download code that is ready to paste into your .htaccess file.

What Are .htaccess Redirects?

.htaccess redirects are rules in a configuration file that tell an Apache web server to send visitors and search engine crawlers from one URL to another. The file is plain text, usually sits in your website's root folder, and Apache reads it on each request when your host allows overrides.

Every rule pairs a request with a response status code. A 301 says the page moved permanently, a 302 or 307 says the move is temporary, and a 410 says the page is gone for good. Google's Search Central documentation describes permanent redirects as a strong signal that the new URL should be the canonical one, and temporary redirects as a weaker signal. One typo can break an entire site, so generating the syntax from a form is safer than typing it from memory.

How to Use the .htaccess Redirect Generator

You can build a rule in under a minute by choosing a type, filling in its fields and generating the code. Follow these steps:

  1. Under Redirect Type, choose one button: WWW, HTTPS, Page, Domain, Directory, Trailing Slash, Extension, Block IP, Hotlink or Errors.
  2. Fill in the fields that appear. For WWW, pick Redirect www to non-www or the reverse, type your Domain Name without www or http://, and leave Use HTTPS in redirect URL checked if your site has an SSL certificate.
  3. For a Page redirect, enter the Source Path (such as /old-page), the Destination URL and a Redirect Status Code: 301 Permanent, 302 Temporary, 307 Temporary (Strict) or 410 Gone (Deleted).
  4. Click Generate .htaccess Code or press Ctrl + Enter. If a field is invalid, a message tells you what to fix.
  5. Check the result in the Generated .htaccess Code box, then choose Copy to Clipboard or Download .htaccess.
  6. Back up your current file, paste the new code at the top of the .htaccess file in your site root, save it and test the old URL in a browser. Clear resets the form for the next rule.

Which Redirect Type Do You Need?

The right type depends on what changed on your site. This table shows what each of the main options does:

TypeWhat it doesTypical use
WWWSends one hostname version to the otherPick one canonical host
HTTPSSends all HTTP requests to HTTPSAfter installing SSL
PageSends one old path to a new locationRenamed or removed page
DomainSends a whole domain to anotherRebrand or migration
DirectoryMoves URLs from one folder to anotherRenamed site section
ExtensionSwaps one file extension for anotherMoving .html to .php
Trailing SlashAdds or removes the final slashConsistent URL format

Three more types are not redirects but live in the same file. Block IP denies access to the addresses you list, one per line, and accepts CIDR ranges such as 10.0.0.0/24. Hotlink stops other sites from displaying your images and allows only the domain you enter. Errors assigns custom pages (for example /errors/404.html) to 400, 401, 403, 404, 500 and 503 responses, and any field you leave empty is skipped.

What Is a 301 Redirect and Which Status Code Should You Pick?

A 301 redirect is a permanent move, and it is the default choice when a URL has changed for good. The Page type lets you choose from four codes:

  • 301 Permanent: the content now lives at a new address. Use it for migrations, renamed pages and merged articles.
  • 302 Temporary: the original URL will return. Use it for short promotions or maintenance pages.
  • 307 Temporary (Strict): also temporary, but it tells the browser to repeat the request with the same method, which matters for form submissions.
  • 410 Gone: the page was deleted on purpose and has no replacement. The destination is not used for this code.

Worked Example: Redirect www to Non-www

Say your site is example.com and visitors reach it at both www.example.com and example.com, which splits links between two hostnames. Choose WWW, keep Redirect www to non-www, enter example.com and keep HTTPS checked. The tool returns three lines:

  • RewriteEngine On
  • RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
  • RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

The condition matches any request to the www hostname, and the rule sends it to the same path on https://example.com with a 301. A request for www.example.com/pricing lands on https://example.com/pricing in a single hop.

For a Page redirect, enter /old-page as the source, https://example.com/new-page as the destination and keep 301. The result is one line, Redirect 301 /old-page https://example.com/new-page. Choose 410 instead and the line becomes Redirect 410 /old-page, which tells crawlers the page was removed.

How Do You Read and Act on the Generated Code?

The output is a short block of Apache directives, and each type follows the same pattern: switch the rewrite engine on, set a condition, then apply a rule with a status code. Good output is short, matches what you typed and carries the status code you expect. Review these points before pasting:

  • Hostnames and paths: confirm your domain is spelled correctly and that paths begin with a slash.
  • Status code: a permanent move should show 301. If you see 302, search engines may keep the old URL indexed longer.
  • Protocol: if your site has no SSL certificate yet, uncheck HTTPS or choose http:// for a domain move. Redirecting to an HTTPS address that does not work makes the site unreachable.

If the tool shows an error, read it literally. "Please enter a valid domain name" means the domain needs a format like example.com. A source path error means the path must start with a slash and contain no spaces or quotes. A destination error means you need a full http or https address, or a path starting with a slash.

Who Uses .htaccess Redirects?

Anyone who runs a site on Apache hosting will eventually need them. Typical situations include:

  • An SEO moving a blog from /old-blog to /blog and keeping its link value.
  • A site owner who finished installing an SSL certificate and wants every HTTP request sent to HTTPS.
  • A business that changed its domain and needs every old URL to land on the new site.
  • A developer converting .html pages to .php without breaking bookmarks.
  • A webmaster who wants to block an abusive IP range, protect image bandwidth or show branded 404 and 503 pages.

Best Practices, Common Mistakes and Troubleshooting

Most redirect problems come from order, duplication or a missing backup. Keep these habits:

Test and compare before going live

Copy your current file before every edit. After pasting, compare the old and new versions with a code diff tool to confirm only your new lines were added. Then load the old URL in a private window and check that it lands where you expect.

Avoid chains and loops

Redirect the old URL straight to the final destination instead of through a middle step. If you combine rules, place the www rule above the HTTPS rule so http://www requests reach the final address in one hop. A loop, where the browser reports too many redirects, usually means two rules point at each other, or a CDN or hosting panel also forces HTTPS.

Fix a 500 error quickly

If the site returns a 500 error after you paste, remove the new lines or restore your backup first. Then check for pasted text with curly quotes, a duplicated RewriteEngine On alongside conflicting rules, or a host that does not allow overrides in .htaccess.

Other common mistakes

  • Entering www.example.com or https:// in the WWW domain field. Type only example.com.
  • Using a 302 for a permanent move.
  • Redirecting deleted pages to the home page when a 410 or a relevant page is more honest.
  • Forgetting that a directory redirect needs names without leading or trailing slashes, such as old-blog and blog.

If you also manage cross-origin access on Apache, the CORS header generator produces rules that sit in the same file.

Limitations to Keep in Mind

This generator writes rules for Apache. Nginx does not read .htaccess files and needs its own syntax, and some managed hosts restrict which directives you can use. It creates the code only; it does not read your existing file, detect conflicts with other rules or confirm that your server has the needed modules enabled. For a large migration with hundreds of old URLs, generate and test a few representative rules first, then build out the rest.

With the right type and status code, a correct redirect takes only minutes. Choose a type above, generate your code, back up your file and test the result. You can find more utilities like this in the web developer tools collection.

Frequently Asked Questions

What is a 301 .htaccess redirect?
A 301 .htaccess redirect is a rule telling Apache that a URL has moved permanently. Browsers and search engines are sent to the new address, and Google treats it as a strong signal that the new URL should replace the old one. Use it for migrations, renamed pages and merged content.
How do I redirect a page using .htaccess?
Choose the Page type, enter the old path in Source Path, add the new address in Destination URL, keep 301 and click Generate .htaccess Code. Paste the single line into your .htaccess file, save it, and test the old URL in a browser.
Where do I put the generated code in my .htaccess file?
Paste the code near the top of the .htaccess file in your website's root directory. Back up the existing file first. If you add several rules, put the www rule above the HTTPS rule to avoid extra redirect hops.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent move and a 302 is temporary. Use 301 when the old URL will never return. Use 302 for short-term changes such as a maintenance page. The tool also offers 307 for strict temporary moves and 410 for deleted pages.
Why does my site show a 500 error or too many redirects after I paste the code?
A 500 error usually means a syntax problem or a host that blocks the directives. Too many redirects means two rules or a CDN setting conflict. Remove the new lines or restore your backup, then add the rules one at a time and test each.
Is this .htaccess redirect generator free, and does it work on Nginx?
The generator is free and needs no sign-in. It creates rules for Apache servers only. Nginx does not read .htaccess files, so you would need Nginx configuration syntax instead. Some hosts also limit which Apache directives you can use.
Recommended

Explore VPN options

A VPN changes your network exit. It does not guarantee anonymity.

Hide Your IP Encryption Network coverage
Protect My IP Now