Organizational Research By

Surprising Reserch Topic

.htaccess rewrite to redirect root URL to subdirectory


Trying to get

www.example.com

to go directly to

www.example.com/store

I have tried multiple bits of code and none work. Please help!

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]

asked Apr 18, 2015 in htaccess by rajesh
0 votes
43 views



Related Hot Questions

6 Answers

0 votes
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]
answered Apr 18, 2015 by rajesh
0 votes
Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ store [L]
If you want an external redirect, set the R flag there as well:

RewriteRule ^$ /store [L,R=301]
answered Apr 18, 2015 by rajesh
0 votes
Here is what I used to redirect to a subdirectory. This did it invisibly and still allows through requests that match an existing file or whatever.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdir/index.php [L]
answered Apr 18, 2015 by rajesh
0 votes
Here is what I used to redirect to a subdirectory. This did it invisibly and still allows through requests that match an existing file

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdir/index.php [L]
answered Apr 18, 2015 by rajesh
0 votes
This seemed the simplest solution:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.example.com/store [R=301,L]
answered Apr 18, 2015 by rajesh
0 votes
I think the main problems with the code you posted are:

the first line matches on a host beginning with strictly sample.com, so www.sample.com doesn't match.

the second line wants at least one character, followed by www.sample.com which also doesn't match (why did you escape the first w?)

none of the included rules redirect to the url you specified in your goal (plus, sample is misspelled as samle, but that's irrelevant).

For reference, here's the code you currently have:

Options +FollowSymlinks
RewriteEngine on

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

RewriteCond %{HTTP_HOST} ^(.+)\www.sample\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]
answered Apr 18, 2015 by rajesh

...