Setup a domain redirect using htaccess?

You can setup a domain redirect in a couple of ways. We’ll outline these below:

To redirect domain with htaccess on your FistHost account, you can also use the control panel redirect tools. For more hosting tutorials, visit the Fist Host blog. For official Apache documentation, see Apache HTTP Server Docs.

How do I setup a domain redirect using .htaccess file?

A .htaccess file is an important Apache configuration file usually resides within the public_html folder of your site, it’s a way to add specific rules on a per-hostname basis. A .htaccess rule allows for further configuration of your redirect should you need a more specific redirect. Below are some common examples you may need to add.

Redirect your website to a new domain

To redirect your website to another domain using a .htaccess rule you’d want to add the following rule to your .htaccess file and then save the file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]

Force www. instead of non-www.

You could achieve this by editing the site and home URL (if your site is WordPress), but it can also be achieved by using the following rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301,NC]

Force HTTPS

You can use the Force HTTPS tool from within the control panel to always enable https://, however you can also add the following rule:

RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

How to Test Your Redirect

After you redirect domain with htaccess, test that the redirect works correctly. Open a private or incognito browser window and visit the old domain. You should be automatically sent to the new domain. Check that the URL in the address bar shows the new domain. Test both the www and non-www versions, as well as http and https, to ensure all variants redirect properly. You can also use online HTTP status checkers to confirm the server returns a 301 (permanent) or 302 (temporary) status code. Clear your browser cache if the old page still loads, as browsers may cache the previous version.

Frequently Asked Questions

What is a .htaccess file?

A .htaccess file is an important Apache configuration file usually resides within the public_html folder.

How do I redirect my website to a new domain using htaccess?

To redirect your website to another domain, add the 301 redirect rules shown in this guide to your .htaccess file.

How do I force HTTPS using htaccess?

You can use the Force HTTPS tool from within the control panel to always enable https://, or add the HTTPS rewrite rules to your .htaccess file.

Related Guides

Important Safety Notes

Always download a copy of your .htaccess file before editing it — a single typo can take your whole site offline with a 500 error. If that happens, restore the backup immediately via File Manager and the site will recover.

Place redirect rules near the top of the file, before WordPress’s own rules, so they run first. After saving, test the redirect in a private browser window and confirm the old URL lands on the new one. Avoid chaining multiple redirects (A to B to C), since each hop slows visitors down and dilutes SEO value — always redirect old URLs straight to their final destination.

One last tip: keep a dated changelog comment at the top of your .htaccess file noting what each rule does. Future you will thank present you when troubleshooting redirect issues six months from now.

Read Previous

Solution for 500 Internal Server Error in WordPress

Read Next

Cheap WordPress Hosting for Everyone

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular