How to Redirect a URL with .htaccess (301, HTTPS and www)

A redirect sends visitors and search engines from an old address to a new one. On Apache and LiteSpeed hosting, the .htaccess file is where you set them up.

↪️Free .htaccess Redirect Generator
301 redirects, force HTTPS and www rules.
Open tool →

When you need a redirect

After renaming or deleting a page, moving to a new domain, switching to HTTPS, or choosing between www and non-www. Without one, visitors hit a 404 and the old page's ranking is lost.

Edit safely

Open your hosting file manager, show hidden files and download a copy of .htaccess before changing anything. If the site shows a 500 error after an edit, restore the copy.

Generate the rules

In the .htaccess Redirect Generator, tick Force HTTPS, choose a www rule and list old and new paths. Paste the output at the very top of the file, above any WordPress block.

Test

Open the old URLs in the Redirect Checker. You want a single 301 hop to the final address – chains of several redirects slow the page and dilute SEO value.

Frequently asked questions

301 vs 302?

301 is permanent and passes ranking value; 302 is temporary.

How long should I keep redirects?

At least a year; indefinitely for pages with backlinks.

My host uses Nginx – what now?

Redirects are set in the server config or your host's control panel instead.

↪️Free .htaccess Redirect Generator
301 redirects, force HTTPS and www rules.
Open tool →

More guides