Redirect domain to subfolder


Last night I was looking for a way to redirect a domain (example.com) to example.com/folder but without actually redirecting the user to that folder.

So I thought that the best way to go about is actually treading every request as example.com/folder.

Anyway enough said here is the result.

1
2
3
4
5
6
7
8
# Redirect to a different folder
# of the current domain that was requested
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /folder/$1 [L]
</IfModule>

Place the above in a .htaccess file in the root of your webserver.

Pretty need isn’t it? It only took 4 lines. 😄


See also