Basic redirects with .htaccess Print

  • 0

The .htaccess file is a configuration file that lives in public_html/ and lets you control how your server responds to certain requests. Redirects are one of its most common uses: forwarding visitors from one URL to another without them noticing the change.

How to edit it: in cPanel > File Manager, enable "Show hidden files" in the preferences, go into public_html/ and find .htaccess. If it does not exist, create it with that exact name (starting with a dot). Make a backup before touching it — a mistake here can take the whole site down.

Redirect the entire site to a new domain

RewriteEngine On
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]

The 301 indicates a permanent redirect — Google will update its index and transfer the SEO to the new domain.

Redirect a specific page

Redirect 301 /old-page.html https://yourdomain.com/new-page.html

Force www (or remove it)

# Force www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]

Redirect a whole folder

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

Tips:

  • Always use 301 (permanent) unless you know the change is temporary (then 302).
  • After editing .htaccess, test the site in incognito mode — browsers aggressively cache redirects.
  • If you break something, restore the backup or delete the .htaccess entirely (the site will fall back to the default configuration).

Something not adding up? Open a ticket with the exact contents of your .htaccess and we will lend a hand.


Was this answer helpful?

« Back