Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: sorting out mod rewrite
PostPosted: Thu Dec 22, 2005 8:16 am 
Offline
Senior Member
User avatar

Joined: Tue Aug 17, 2004 11:37 pm
Posts: 262
Website: http://www.our-lan.com
WLM: nf@our-lan.com
Location: Brisbane, Australia
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 follows
Code:
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
Code:
[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


Top
   
PostPosted: Thu Dec 22, 2005 11:11 am 
Offline
Senior Member

Joined: Sat Jun 05, 2004 12:49 am
Posts: 333
Internat wrote:
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 follows
Code:
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


You either need to put parens around the matching in the rewriterule:

Code:
RewriteRule (.*)         http://www.our-lan.com/$1 [L,R]


Or change the backreference to refer to the RewriteCond as per the documentation.

Code:
RewriteRule .*         http://www.our-lan.com/%1 [L,R]


Top
   
 Post subject:
PostPosted: Thu Dec 22, 2005 7:02 pm 
Offline
Senior Member
User avatar

Joined: Tue Aug 17, 2004 11:37 pm
Posts: 262
Website: http://www.our-lan.com
WLM: nf@our-lan.com
Location: Brisbane, Australia
yeah i was told that just after i posted, but the problem still exists.. i also tried playing arround with the conidition in the first rewritecond changing it from (.+) to (.*) but neither worked...

both basicly do the same thing and it ends up redirecting blog.our-lan.com to www.our-lan.com// <== note the double slash


Top
   
 Post subject:
PostPosted: Fri Dec 23, 2005 1:39 am 
Offline

Joined: Fri Dec 23, 2005 1:16 am
Posts: 1
Already sent this to internat but in case someone else with this problem is scanning the forums looking for the solution here it is.

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 http://subhost.host.com/path/to/script.php then RewriteRule checks against "/path/to/script.php"). The answer to this is tricksie and but very cute.
(using the particulars of Internats example above)
Code:
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group