Hosting
Servers
Web Development Pricing
Resources
Get started → Log in
Home/Calculators/.htaccess redirect generator
Free tool · runs in your browser

.htaccess redirect generator
301, HTTPS, www and domain moves.

Tick the rules you need, then copy or download a ready .htaccess. Nothing is sent anywhere; it all runs on this page.

1. HTTPS and www

Leave it empty for a general rule. Enter it to limit the www rule to that one domain.

2. Move the whole site to a new domain

3. Single page redirects

Use 301 for a permanent move and 302 for a temporary one. The old path starts with /. The new target is a path or a full https:// URL.

The download is named htaccess.txt because many systems hide files that start with a dot. Upload it to your site's root folder and rename it to .htaccess. Back up any existing .htaccess first.

What .htaccess is

.htaccess is a plain text file that holds server settings for one folder and everything inside it. It started with the Apache web server, which reads it on every request, so a change works at once without restarting anything. LiteSpeed, the server used by many cPanel hosts, reads .htaccess too. Nginx does not. On Nginx the same redirects go into the server configuration, using different syntax, so this generator's output will not work there.

Where it lives

Put the file in the document root of your site. On cPanel hosting that folder is usually public_html. Rules in a file apply to its folder and all folders below it, so a file in public_html covers the whole site. The name is exactly .htaccess, with the leading dot and no extension.

301 vs 302 redirects for SEO

A 301 says the page has moved for good. Search engines move the old URL's place in results to the new one, so use it for renamed pages, HTTPS, www choices and domain moves. A 302 says the move is temporary, so search engines keep the old URL. Use it for short jobs such as maintenance or a test. Using a 302 for something permanent is a common mistake, because it can leave the old URL in search results for longer.

Redirect vs RewriteRule

Redirect comes from mod_alias. It is simple: it matches the start of the path and sends the visitor to the new place, so Redirect 301 /old.html /new/ is easy to read. It cannot look at the host name, the protocol or the query string.

RewriteRule comes from mod_rewrite. It matches patterns, and with RewriteCond lines in front it can check conditions, such as whether the request is HTTPS or which host name was used. That is why HTTPS, www and domain moves use it, and one-off page moves use Redirect. The generator picks the right one for each job. Rewrite rules start with RewriteEngine On, which it writes once at the top.

How to test your redirects

Open the old URL in a private (incognito) window, because browsers cache 301 redirects hard and may show an old result in a normal window. For the exact response, run curl -I http://example.com/old.html. You should see a 301 status and a Location: line with the new URL. Add -L to follow every hop and see the whole chain.

curl -I http://example.com/old.html
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new/

Avoiding redirect loops and chains

A loop happens when rule A sends a visitor to a URL that rule B sends straight back. The browser then shows "too many redirects". The classic case is forcing www and non-www together, which is why the tool warns you and adds neither. A chain is a series of hops, such as http to https to www. Each hop slows the visit and passes less value to search engines, so point every rule at the final address. The tool puts the www rule before the HTTPS rule, so http://example.com reaches https://www.example.com in one hop. Also update old redirects when a target moves again, so A goes straight to C instead of A to B to C.

Back up before you edit

Apache and LiteSpeed read the file on every request, so a typo can take your whole site down with a 500 error. Download a copy of the current .htaccess before you change it. If the site breaks, put the old copy back and it recovers at once. Add one block at a time and reload the site after each, so you know which line caused a problem.

WordPress and .htaccess

WordPress writes its own block into .htaccess, between # BEGIN WordPress and # END WordPress. WordPress can rewrite what is inside those markers, for example when you save the permalink settings, so never edit inside them. Put your custom rules above the block. Redirect rules placed there run before WordPress takes over the request, which is what you want.

Using it on RapidServer

RapidServer web hosting is cPanel hosting on LiteSpeed (from ₹49/mo (3-year plan) plus 18% GST), with free SSL, so you can turn on the HTTPS rule once the certificate is active. Open the cPanel File Manager, go to public_html, and edit or upload your .htaccess there. On WordPress, including our WordPress hosting, keep your own rules above the # BEGIN WordPress block. If you also want to control what search engines crawl, try the robots.txt generator, and find more free tools on the calculators page.

Need a home for your website?

cPanel web hosting on LiteSpeed and NVMe in Mumbai, with free SSL and a 7-day money-back guarantee.

See web hosting

Frequently asked questions

Where do I put the .htaccess file?+
In the document root of your site, which is usually public_html on cPanel hosting. Rules apply to that folder and every folder below it.
How do I redirect HTTP to HTTPS?+
Tick "Force HTTPS" above. It adds a RewriteCond that checks whether HTTPS is off, and a RewriteRule that sends the same address to https:// with a 301. Make sure your SSL certificate is working first.
Should I use www or non-www?+
Either is fine for search engines. What matters is picking one and redirecting the other to it, so you do not have two copies of every page. Never force both at once.
Why does my redirect not work?+
Common causes are a file saved with the wrong name (it must be .htaccess), a file in the wrong folder, a browser showing a cached result, or a server that ignores .htaccess, such as Nginx. Test with curl -I or an incognito window.
Does .htaccess work on Nginx?+
No. Nginx does not read .htaccess. The same redirects are written in the Nginx server configuration instead. Apache and LiteSpeed both read .htaccess.
Will a 301 redirect hurt my rankings?+
A correct 301 to a matching page is the normal way to move a URL, and search engines follow it. Problems come from long chains, redirects to unrelated pages and loops.
How long should I keep a 301 redirect?+
Google has said to keep redirects in place for at least a year. Many people leave them for good, because they cost almost nothing and old links keep working.
Chat with sales