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.
cPanel web hosting on LiteSpeed and NVMe in Mumbai, with free SSL and a 7-day money-back guarantee.
See web hosting