Forum: Nitro Apache question

Posted by George Moschovitis (Guest)
on 2007-11-05 22:28
(Received via mailing list)
Dear devs,

I have a small apache question, hopefully someone can help.

I would like to rewrite urls like:

username.mysite.com

to

www.mysite.com/view/username

everyone knows the exact RewriteCond/RewriteRule directives?

thanks in advance,
-g.
Posted by chris (Guest)
on 2007-11-05 22:33
(Received via mailing list)
I think what you want is name based virtual host routing.  I have a 
sample
configuration file at home.  I'll post it here when I get there.

Chris
Posted by George Moschovitis (Guest)
on 2007-11-05 23:00
(Received via mailing list)
please do so...

thanks,
-g.
Posted by chris (Guest)
on 2007-11-06 04:34
(Received via mailing list)
I'm on a debian based system which includes the following snip from the 
main
conf file.  The "ServerName carl" entry is the hostname of the incoming 
http
request.  The "VirtualHost *" is defining what ip interface to listen on
btw.

chris@carl:/etc/apache2/sites-available$ cat carl
<VirtualHost *>

    LoadModule proxy_http_module 
/usr/lib/apache2/modules/mod_proxy_http.so

    ServerName carl

    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://localhost:9000/

    <Location />
        Order allow,deny
        Allow from 192.168.0.0/16
    </Location>
</VirtualHost>


Your should look like this...


>     <Location />
>         Order allow,deny
>         Allow from *
>     </Location>

    <PUT_REWRITE_RULE_HERE to make / => /view/username />
> </VirtualHost>
>

This should get you going, let me know if you have more problems I'll go
into more detail.

-Chris


On Nov 5, 2007 4:59 PM, George Moschovitis 
<george.moschovitis@gmail.com>
Posted by George Moschovitis (Guest)
on 2007-11-06 07:55
(Received via mailing list)
I don't want a VirtualHost.
I will have 100.000 different usernames. I can't add a VirtualHost for 
each
one of them.

I need a single rewrite rule.

any ideas?

-g.
Posted by chris (Guest)
on 2007-11-06 15:27
(Received via mailing list)
RewriteCond %{HTTP_HOST}   !^(.*).mysite.com [NC]
RewriteRule ^/(.*)$         http://www.mysite.com/view/%1/$1 [L,R]

To have http://www.mysite.com/    not be rewritten we may need to put in
another line to tell the RewriteCond to skip direct http calls to
www.mysite.com.  Unfortunately I don't have anywhere to test this, so 
you'll
have to let me know how it goes and I can keep looking into the skip
directive.

-Chris


On Nov 6, 2007 1:54 AM, George Moschovitis 
<george.moschovitis@gmail.com>
Posted by Robert Mela (Guest)
on 2007-11-06 16:40
Attachment: rob.vcf (117 Bytes)
(Received via mailing list)
The closest I see to what you're specifying is
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

Unfortunately it does not do an external redirect -- it changes the path
internally.    But, if you can inject that path change before
mod_rewrite then mod_rewrite can use it to generate the external
redirect.    I think a vhost such as <VirtualHost *.mydomain.com> that
will catch all the username domains but I would have to verify that.

If you can sacrifice the external redirect then mod_vhost_alias might be
all you need.  I'm not sure what all your requirements are or what
tradeoffs are acceptable.

Fortunately the path translation feature offers use of substrings -- so
100,000 domains don't have to resolve to 100,000 top-level directory
entries.

I can look at it tonight.   But, if it turns out the stench of
configuration hackery is too great to bear, I can whip up a simple
Apache module that does exactly what you need.   The logic involves will
amount to about 10 or 20 lines of C.   This often winds up being a lot
cleaner.   In exchange however I will need the many_to_many relation
fixed in Og, to the point that isTaggable works correctly.
Posted by chris (Guest)
on 2007-11-06 16:40
(Received via mailing list)
I just noticed in apache 2.0 the "!" in front of the RewriteCond 
expression
should be removed.

FYI
Posted by Robert Mela (Guest)
on 2007-11-08 17:13
Attachment: rob.vcf (117 Bytes)
(Received via mailing list)
Has this been solved?
Posted by George Moschovitis (Guest)
on 2007-11-08 17:17
(Received via mailing list)
>
> Has this been solved?


nope, I did this with nitro:

module Raw::Request

  # Implement user mapping:
  # username.me.gr -> me.gr/user/view/username

  def uri
    ruri = @headers["REQUEST_URI"]
    return ruri if host_uri =~ /http:\/\/(www)\./
    if host_uri =~ /http:\/\/(.+)\.me\.gr\/?/ and ruri == "/"
      "/user/view/#$1"
    else
      ruri
    end
  end
end


-g.
Posted by Judson Lester (Guest)
on 2007-11-28 21:08
(Received via mailing list)
On Nov 8, 2007 8:17 AM, George Moschovitis 
<george.moschovitis@gmail.com>
wrote:

> Has this been solved?
>
>
> nope,
>

Hey, I'm not dead!  And I know Apache pretty well.  If, in the face of a
Nitro solution, you still want an Apache one, I humbly present (cribbed 
and
munged from their docco):

RewriteEngine On

RewriteMap lowercase int:tolower

RewriteCond %{lowercase:%{HTTP_HOST}} !^www.mysite.com$
RewriteCond %{lowercase:%{HTTP_HOST}} ^([^.]*)\.mysite.com$
RewriteRule ^/(.*)$ http://www.mysite.com/view/%1/$1 [R]

Judson
Posted by George Moschovitis (Guest)
on 2007-11-28 22:45
(Received via mailing list)
interesting,

I will try this.

thanks,
-g.
This topic is locked and can not be replied to.