.htaccess redirect to folder

For those who are looking to redirect to a folder, do this :

# 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]
RewriteRule ^(/)?$ folder/index.html [L]

Change the domain with your domain-name.
Change the  folder with the folder where you like to place your website.
Change .com in the domain-name extension you use. (For example .eu or .us)


Popular Posts