KeirDavis
KeirDavis

Reputation: 665

.htaccess on redirect loop when changing subdomain to subdirectory

So I'm using htaccess to change the 'm' subdomain to the 'mobile' subdirectory.

I've created this code to run in Htaccess but it is returning an inside loop.

RewriteCond %{HTTP_HOST} ^m\.
RewriteRule ^(.*) mobile/$1 [NC,L,QSA]

I'm attempting to redirect all file requests with the 'm' subdomain to go to the 'mobile' directory.

error.log

[Thu Jan 15 19:01:29 2015] [error] [client xxx.xxx.xxx.xxx] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

How would I go about fixing this problem?

Upvotes: 1

Views: 115

Answers (1)

anubhava
anubhava

Reputation: 785631

You need:

RewriteCond %{HTTP_HOST} ^m\. [NC]
RewriteRule ^((?!mobile/).*)$ mobile/$1 [NC,L]

i.e. route to /mobile/ only if request doesn't already have /mobile/.

Upvotes: 2

Related Questions