Apache question

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.

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

please do so…

thanks,
-g.

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>

Your should look like this…

<Location />
    Order allow,deny
    Allow from *
</Location>
<PUT_REWRITE_RULE_HERE to make / => /view/username />

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 M.
[email protected]

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 M.
[email protected]

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.

I just noticed in apache 2.0 the “!” in front of the RewriteCond
expression
should be removed.

FYI

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.

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.

Has this been solved?

interesting,

I will try this.

thanks,
-g.

On Nov 8, 2007 8:17 AM, George M.
[email protected]
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