Blog

Tutorials, guides, product news and engineering insights from the team that runs your hosting.

Performance and Technical SEO

301 Redirects with .htaccess: HTTPS, www and Old URLs

6 November 2026 2 min read
Share this post

When a page's address changes, visitors and search engines need to reach the new one. The standard way is a 301 (permanent) redirect. Our LiteSpeed server reads Apache-compatible .htaccess rules, so the examples below work as they are.

Before you start

  • The .htaccess file sits in your site's root folder (usually public_html). If you can't see it in File Manager, turn on hidden files under Settings.
  • Make a copy of the file before editing. A single typo can make the site return "500 Internal Server Error"; putting the old copy back fixes it.
  • On WordPress, put your own rules outside the # BEGIN WordPress block, preferably above it. WordPress rewrites the inside of that block itself.

Redirecting HTTP to HTTPS

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

If your site is behind Cloudflare with "Always Use HTTPS" turned on, you don't need this rule. Adding it while Cloudflare's SSL mode is "Flexible" causes a redirect loop; set the mode to "Full".

From www to non-www (or the reverse)

Having your site load at a single address stops the same content appearing at two.

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

For the reverse, always loading with www:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

On WordPress, the address in Settings › General must match the form you chose.

Redirecting a single old page

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

When you move a site or change its URL structure, redirect each old page that gets traffic to its closest new equivalent. Sending them all to the home page is a weak solution for users and search engines alike.

From an old domain to a new one

After adding the old domain to your account as an alias:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [L,R=301]

Don't block SSL validation

Broad rules that redirect every request can also block access to the free SSL certificate's validation file. If that happens, add this exception above the rule:

RewriteCond %{REQUEST_URI} !^/\.well-known/

See our AutoSSL troubleshooting article for details.

Testing

Browsers cache 301 redirects, so test changes in a private window. If you see a "too many redirects" error, two rules are triggering each other; remove the rule you added last and try again.

Comments0

No Comments Yet

Be the first to share your thoughts.

Join the Discussion

Please sign in or sign up to leave a comment.

Never Miss a Post

Get our latest tutorials, guides and product news in your inbox.

You're subscribed to our newsletter.