Skip to content

Tutorials Website building Intermediate1 min read

How to Set Up 301 Redirects with .htaccess

Redirect single pages, whole folders, non-www to www and HTTP to HTTPS with .htaccess on Apache and LiteSpeed — with copy-ready examples.

By ZSOLNET Editorial Team Updated

Key takeaways

  • 301 is permanent and passes search value to the new URL.
  • Keep redirects in one hop — chains slow pages and waste crawl budget.
  • Back up .htaccess before editing; a typo causes a 500 error.

.htaccess lives in your site’s document root. Open it with cPanel’s File Manager (enable Show Hidden Files).

Redirect one page

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

Redirect a folder

RedirectMatch 301 ^/blog/(.*)$ https://example.com/articles/$1

Force HTTPS and www

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

Move a whole domain

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

Test

Run the redirect checker on the old URL. It should show one 301 hop straight to the final page returning 200. Clear your browser cache when testing — browsers remember 301s.

Frequently asked questions

301 or 302?

Use 301 when a page has moved for good. Use 302 only for temporary moves, such as a short promotion.

Does this work on Nginx?

No. Nginx ignores .htaccess. Use return 301 rules in the server block instead.

Share X LinkedIn Facebook

Log in to your account

Manage your domains, hosting and invoices in one place.

Secure connection straight to the ZSOLNET client area.

No account yet?