How To Redirect Your Domain To A Subfolder Using htaccess

In this tutorial, we are going to show you a simple way to redirect your primary domain to a subfolder on that domain. For the purposes of this tutorial, it will redirect to a subfolder at /blog.

This is useful if your WordPress blog is installed to a subfolder and you want the main domain to forward to it.

In your public_html folder (also called the “root directory” or “document root”), you need to create a file called .htaccess. You can do so by using the File Manager in cPanel.

From this file, we are going to use a few lines to redirect those requests in a search engine friendly way.

Add the following lines to that file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ blog [L]

The only change you need to make is to change “yourdomain.com” to your domain. This will then redirect everything from the domain to the folder /blog at that domain. If you want to change that folder just edit the “blog” part.

If you enjoyed this article, then you’ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! Check out our services.