Rewrite rules, experts helps need please :)

Hello,

We try to redirect all requests from http://SBX.domain.com to /home/account/otherdomain.com/html/SBX/

The SBX.domain.com has a CNAME on otherdomain.com so it goes directly in the good documet_root of otherdomain.com.

So it’s like a subdomain redirection as we’d like all request goes in SBX/ direrectory

We’d also need (for some reasons to long to explain here) that these rules will be in an HTACCESS file, not in the vhost config file.

[B]The crazy thing is that this rule works just fine in the VHOST config file but not in an HTACCESS file :[/B]

RewriteCond %{HTTP_HOST} ^([0-9A-Za-z-]+).domain.com [NC]
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%1/$1 [L]

If we comment this rules in the vhost config file, enter this rules in an htaccess file in /home/account/otherdomain.com/html/.htaccess file then restart Apache, this rules doesn’t work anymore

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^([0-9A-Za-z-]+).domain.com [NC]
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%1/$1 [L]

We have an ERROR 500 with these logs

[Sat Jan 13 20:13:36 2007] [error] 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.
[Sat Jan 13 20:13:36 2007] [error] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use ‘RewriteOptions MaxRedirects’ to increase the limit if neccessary.

It is very strange to have the same rule working in VHOST and not in HTACCESS ?!!??

Any idea on how to have this rules working in an htacesse file ?

Thanks

Pascal

================
in fact we put the rewrite rule for this vhost in loglevel 3 and wrote the log in a file.

We found this

100.111.221.193 - - [13/Jan/2007:20:16:52 +0100] [blog.domain.com/sid#ba1510][rid#1400318/initial/redir#9] (2) [per-dir /home/account/domain.com/html/] strip document_root prefix: /home/account/domain.com/html/blog/blog/blog/blog/blog/blog/blog/blog/blog/blog/ -> /blog/blog/blog/blog/blog/blog/blog/blog/blog/blog/
100.111.221.193 - - [13/Jan/2007:20:16:52 +0100] [blog.domain.com/sid#ba1510][rid#1400318/initial/redir#9] (1) [per-dir /home/account/domain.com/html/] internal redirect with /blog/blog/blog/blog/blog/blog/blog/blog/blog/blog/ [INTERNAL REDIRECT]

Indeed Apache told us

Note: Pattern matching in per-directory context
Never forget that Pattern is applied to a complete URL in per-server configuration files. However, in per-directory configuration files, the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting - without this, you would always have to match the parent directory which is not always possible.

So the first time, a per directory rewrite strip the doc_root then re-add the path

The first time we had
/ rewrite to blog/

Then Mod_Rewrite resend the request to Apache

the second time we have
/blog rewrite to blog/blog

etc…

Apache with a “LogLevel debug” gives us

[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/blog/blog/blog/blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/blog/blog/blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/blog/blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /blog/
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/server/core.c(2763): [client 90.14.221.193] redirected from r->uri = /
[Sat Jan 13 20:27:07 2007] [debug] /usr/src/redhat/BUILD/httpd-2.0.59/modules/mappers/mod_rewrite.c(1788): [client 90.14.221.193] mod_rewrite’s internal redirect status: 10/10.
[Sat Jan 13 20:27:07 2007] [error] [client 90.14.221.193] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use ‘RewriteOptions MaxRedirects’ to increase the limit if neccessary.

Any idea how to not have this loop ?

Thanks by advance

These seems to work

RewriteCond %{HTTP_HOST} ^([0-9A-Za-z-]+).domain.com [NC]
RewriteCond %{REQUEST_URI} !^/blog
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*)$ %1/$1 [L]

Pascal