.htaccess rewrite to redirect root URL to subdirectory

AlphaSmith picture AlphaSmith · Jun 13, 2009 · Viewed 541.9k times · Source

Trying to get

www.example.com

to go directly to

www.example.com/store

I have tried multiple bits of code and none work.

What I've tried:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(.+)\www.example\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]

What am I doing wrong?

Answer

Sander picture Sander · Aug 25, 2009

You can use a rewrite rule that uses ^$ to represent the root and rewrite that to your /store directory, like this:

RewriteEngine On
RewriteRule ^$ /store [L]