views:

134

answers:

3

The title doesn't give justice to the question.

I have a site and I want it to be redirected to a subfolder.

I have this right now:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysite.net$
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.net\/subfolder$1" [R=301,L]

The problem is that it results in a infinite redirect loop. It gets to / and redirects it to a subfolder and when it arrives there, it again redirects it.

How do I stop the redirection as soon as it gets to my designated subfolder.

A: 

Add an exclusion rule for the target.

RewriteEngine on

RewriteRule ^/subfolder - [L]

RewriteCond %{HTTP_HOST} ^mysite.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysite.net$
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.net\/subfolder$1" [R=301,L]
Lachlan Roche
sorry that didn't work at all
Thorpe Obazee
+1  A: 

I think I got it right now:

RewriteEngine on
RewriteRule !^(subfolder/) http://www.mysite.net/subfolder/ [L,R]

Got a little inspiration from a deleted answer here:

Thorpe Obazee
A: 

Also, for the RewriteCond, you can do this:

RewriteCond %{HTTP_HOST} ^(www.)?mysite.net$

to save a line

Manu