sorting out mod rewrite
what im trying to do is redirect $1.our-lan.com to
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.our-lan\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www
RewriteRule .* http://www.our-lan.com/$1 [L,R]
RewriteLog "/home/nf/rewrite.log"
RewriteLogLevel 3
in my logs im getting something like
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (2) init rewrite engine with requested uri /
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (3) applying pattern '.*' to uri '/'
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (2) rewrite / -> http://www.our-lan.com/
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (2) explicitly forcing redirect with http://www.our-lan.com/
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (1) escaping http://www.our-lan.com/ for redirect
[forums.our-lan.com/sid#80cc410][rid#8227cd8/initial] (1) redirect to http://www.our-lan.com/ [REDIRECT/302]
[www.our-lan.com/sid#80cc410][rid#822fcf8/initial] (2) init rewrite engine with requested uri /
[www.our-lan.com/sid#80cc410][rid#822fcf8/initial] (3) applying pattern '.*' to uri '/'
[www.our-lan.com/sid#80cc410][rid#822fcf8/initial] (1) pass through /
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (2) init rewrite engine with requested uri /index.html
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (1) pass through /index.html
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (2) init rewrite engine with requested uri /index.cgi
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (1) pass through /index.cgi
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (2) init rewrite engine with requested uri /index.pl
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (1) pass through /index.pl
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (2) init rewrite engine with requested uri /index.php
[www.our-lan.com/sid#80cc410][rid#8229ce0/subreq] (1) pass through /index.php
3 Replies
@Internat:
ok, .. so ive been bugging ppl in the channel and i have most of it downpat, but im not 100% sure why this is breaking
what im trying to do is redirect $1.our-lan.com to
www.our-lan.com/$1 .. my config is as followsRewriteEngine on RewriteCond %{HTTP_HOST} ^(.+)\.our-lan\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www RewriteRule .* http://www.our-lan.com/$1 [L,R] RewriteLog "/home/nf/rewrite.log" RewriteLogLevel 3
You either need to put parens around the matching in the rewriterule:
RewriteRule (.*) http://www.our-lan.com/$1 [L,R]
Or change the backreference to refer to the RewriteCond as per the documentation.
RewriteRule .* http://www.our-lan.com/%1 [L,R]
both basicly do the same thing and it ends up redirecting blog.our-lan.com to
The problem with what you're doing is that RewriteRule works off of the Request-URI not the entire URL. (i.e. if you type in
(using the particulars of Internats example above)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.our-lan\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.our-lan.com(.*) http://www.our-lan.com/$1$2 [L,R]
The first RewriteRule injects the Hostname into the URI and then the second one strips it out but saves the parts that we're interested in. All very devious but it works.