SEOLyzerPro

100% Free forever - No account required

Use 47 free online tools: meta tag and robots.txt generators, image and text tools, JSON converters, calculators and unit converters. No signup needed

htaccess Redirect Generator

Create .htaccess rules to redirect www and non-www

Select redirect type:

htaccess Redirect Generator

What this tool does

The htaccess Redirect Generator creates redirect rules for an Apache web server, so that visitors and search engines who request an old address are sent to a new one. You enter the old and new addresses, choose a redirect type, and copy the generated code into your .htaccess file. It reduces syntax mistakes, which matter because a single wrong character in this file can break a whole site.

How to use it

  1. Choose the type of redirect you need.
  2. Enter the old path and the new address.
  3. Select the status code, normally 301 for a permanent move.
  4. Generate the code and copy it.
  5. Make a backup of your current .htaccess file, then paste the new rules into it, save, and test the redirect in your browser.

What is a .htaccess file?

.htaccess is a configuration file that Apache servers read to apply rules to a folder and everything in it. It sits in your site’s root folder and can control redirects, access rules, caching and more. The file name starts with a dot, so some file managers hide it. Enable “show hidden files” to find it. Servers that do not use Apache, such as Nginx, ignore .htaccess, and need rules in their own configuration instead. If you use LiteSpeed, it reads most Apache rules. If you are not sure, ask your host.

Examples of generated rules

Redirect one page permanently:

 
Redirect 301 /old-page https://www.example.com/new-page

Force HTTPS:

 
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect non-www to www:

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

Choosing the right redirect

  • 301 (permanent). Use when a page has permanently moved, when you change domain, or when you consolidate duplicate addresses. Search engines pass signals to the new address.
  • 302 (temporary). Use when the original address will return, such as during a short promotion or test.
  • 410 (gone). Not a redirect, but useful when a page is removed on purpose and has no replacement.

Send people to the most relevant page. Redirecting a removed article to an unrelated page, or to the homepage, confuses visitors and may be treated as a soft 404.

When to use these redirects

  • You changed a page’s URL or slug.
  • You moved from http to https.
  • You want one preferred version of your domain, with or without www.
  • You merged two similar pages.
  • You are moving to a new domain and want the old addresses to land on matching new ones.
  • You changed your permalink structure.

Rules for safe editing

  1. Back up first. Download the existing file before changing it.
  2. Add rules carefully. Put new rules in the right place, normally below existing rewrite rules for your CMS, unless the guide for that CMS says otherwise. In WordPress, keep the block between the “BEGIN WordPress” and “END WordPress” lines untouched, since WordPress may rewrite it.
  3. Edit as plain text with a code editor. Word processors add hidden characters that break the file.
  4. Test straight away. Open the old address in a private window and confirm that it lands on the right place. Then check your homepage and a few other pages.
  5. Keep it tidy. Very long lists of rules can slow down a server. For large migrations, use a pattern-based rule or a redirect plugin or database.

If your site shows a 500 error

A syntax mistake in .htaccess usually causes a 500 Internal Server Error across the site. Restore your backup file at once, using your file manager or FTP. Then compare the rule you added, looking for missing spaces, wrong brackets or a typing error. Check your server’s error log for the exact line.

Avoiding redirect chains and loops

Do not redirect A to B and then B to C. Point A straight to C. A loop, such as A to B and B to A, makes the browser stop with “too many redirects”. Also check that your HTTPS rule and your www rule do not fight each other. The best setup is one hop from any version of the address to the final preferred one.

Update your links afterwards

A redirect helps old links, but it is better to update your internal links, sitemap and canonical tags to the new address as well. If you move to a new domain, use the Change of Address tool in Google Search Console and keep redirects in place for at least a year.

Limits of this tool

The generator writes rules, but it does not test them on your server, and it cannot know your server’s setup, other rules in your file or plugin conflicts. Different hosts handle .htaccess in slightly different ways. We cannot be responsible for site problems caused by code you apply, so always keep a backup.

Frequently asked questions

Where do I put the .htaccess file?
In the root folder of your website, often called public_html or www.

Will my rankings drop after a redirect?
Correct 301 redirects to relevant pages generally preserve the value of the old address, although results can take time to settle.

Can I redirect a whole folder?
Yes, with a pattern-based rule. Test it carefully.

Does a redirect work on Nginx?
No. Nginx needs its own configuration instead of .htaccess.

Related tools

HTTP Status Code Checker, Redirect Checker, Robots.txt Generator, Meta Tag Generator, Text to Slug and Meta Tags Analyzer.