Redirect Root Directory to Sub Directory with .htaccess


Create a .htaccess file under your /public_html/ folder. If you already have one add the following to the top of it.

If not create a text file in Microsoft Notepad and name it simply ".htaccess" with no file extension.

Paste the following in the file:


# Turn on rewrites. 
RewriteEngine on 
# Only apply to URLs on this domain 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
# Only apply to URLs that aren't already under folder. 
RewriteCond %{REQUEST_URI} !^/folder/ 
# Don't apply to URLs that go to existing files or folders. 
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 
# Rewrite all those to insert /folder. 
RewriteRule ^(.*)$ /folder/$1 
# Also redirect the root folder. 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteRule ^(/)?$ folder/index.php [L]

In your application set the site url to http://www.domain.com , remeber to replace domain.com with your domain name and folder with the folder name.