How to redirect domain to subdirectory without changing URL

Here is the simple way to redirect your primary Domain to a sub folder without change the URL. Most of the case we use to keep all files in HTML folder (“root HTML” folder), Better you can create a folder in HTML folder and keep all files in that folder and redirect domain. It is very easy to manage file in future if you host multiple website in same server. You can create folder for each domain and keep file separately and it will be looks very neat and clean.

We can create a folder /blog in root folder to redirect. You can use any folder name. Edit .htaccess file, You will get this file in HTML folder.

Add the following code to .htaccess file:

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

Try another way is to add the following lines:

RewriteEngine On
RewriteRule !^blog/ /blog%{REQUEST_URI} [L,R=301]