HoangHieu
HoangHieu

Reputation: 2840

.htaccess rewrite folder to subdomain Error

I have some stuck. I was config Apache

<VirtualHost *:80>
      ServerAdmin [email protected]
      DocumentRoot /home/abc/Projects/
      ServerAlias *.example.com
      ServerName example.com
      ErrorLog error.log
</VirtualHost>

my .htaccess file

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

my webpage was return Internal Server Error

How I can config .htaccess accept to

update My Error Log

[Sat Aug 22 21:29:58.093791 2015] [core:error] [pid 31081] [client 192.168.83.1:7322] AH00124: 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., referer: http://test.example.com/

Apache/2.4.10 (Ubuntu) Server at test.example.com Port 80

thk's any got a tip

Upvotes: 1

Views: 128

Answers (1)

anubhava
anubhava

Reputation: 785058

You rule is infinitely looping and eventually causing 500 error. To stop that you can use this additional condition:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ %1/$1 [L]

%{ENV:REDIRECT_STATUS} is an internal mod_rewrite variable that is set to 200 after first internal rewrite.

Upvotes: 1

Related Questions