You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by dale's stuff <st...@colony.net> on 2002/09/04 13:22:58 UTC

[users@httpd] Is mod_rewrite the solution for this...?

Hello,

Apache 1.3x on RH Linux 7.2

I have a website with user profile pages that are served from a database. I 
wish to change this around a bit so that instead of having a longer url 
with numbers in it the URL will be styled domain.com/members/nickname/

I am getting the member names all unique in the database, and while I could 
create directories in the members directory for each user, I currently have 
about 15,000 users and expect to grow to even higher numbers as I implement 
various improvements.

I can use my existing tool to say grab the first 1 or 2 letters of the 
nickname to create a directory under ./members/ but then I would need to 
somehow have another process on the server see the url and point to the 
proper place. I can do this with my existing server side tool, but I am 
thinking that accomplishing this in the webserver will probably be faster.

An example would be - domain.com/members/greybear/ where I think I should 
create a folder named ./members/gr/greybear/

Does the above make sense or am I looking to the wrong place to accomplish 
this?

Thanks for any suggestions.

Dale


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is mod_rewrite the solution for this...?

Posted by Hans Juergen von Lengerke <le...@sixt.de>.
dale's stuff <st...@colony.net> on Sep 4, 2002:

> >   RewriteRule ^/members/(([^/]{2})[^/]*)/(.*)$ /members/$2/$1/$3
>
> If I understand this correctly, (I have never used mod_rewrite) this is
> looking in the members folder, getting the first 2 charactors after the /
> then re-writing that to /members/$2 (this is the leading 2 charactors of
> the nickname) /$1 (where this is the nickname value) and $3 ? this is
> anything after the trailing / after the nickname.
>
> Is that correct?

Yes, that is more or less correct. The pattern (the first argument to
RewriteRule) says in English:

   ^           # If a requested URL starts with
   /members/   # the string "/members/"
   (           # [start storing matches in $1]
    (          # [start storing matches in $2]
     [^/]{2}   # match two chars that aren't a "/"
    )          # [end storing matches in $2]
    [^/]*      # match any chars that aren't a "/"
   )           # [end storing matches in $1]
   /           # followed by a "/"
   (           # [start storing matches in $3]
    .*         # any number of any chars
   )           # [end storing matches in $3]
   $           # up to the end of the URL


Check out any tuturials/guides on the web on "Regular Expressions".
Another good resource is Jeffrey Friedls "Mastering Regular Expressions"
from O'Reilly.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is mod_rewrite the solution for this...?

Posted by dale's stuff <st...@colony.net>.
Hello,

Thank you for the reply and sorry for any confusion on what I am trying to 
do.

Currently a profile link is styled as:

  domain.com/members/details.html?id=3434525252434523

I wish to change this to

  domain.com/members/nickname/

on the server the nickname directory would be stored as 
/members/ni/nickname/

The reason for this is the current 15,000 directories I need to create with 
growth expected to triple soon. I did not want that many directories all in 
one master directory. I felt that by splitting them up this way it makes it 
easier on the OS (Linux) and makes it easier if I need to place some of 
these folders on another drive.

Creating the directories is not a problem with the server side tool I am 
already using. I could serve them this was as well, but one of the other 
ideas is to cut down on the number of database queries on the server. I 
will be writing out static pages to these folders as well.


On Wednesday, September 4, 2002, at 04:53  PM, Hans Juergen von Lengerke 
wrote:

> dale's stuff <st...@colony.net> on Sep 4, 2002:
>
>> An example would be - domain.com/members/greybear/ where I think I should
>> create a folder named ./members/gr/greybear/
>
> I'm not entirely sure I understand what you want but maybe this is it:
>
>   RewriteRule ^/members/(([^/]{2})[^/]*)/(.*)$ /members/$2/$1/$3

If I understand this correctly, (I have never used mod_rewrite) this is 
looking in the members folder, getting the first 2 charactors after the / 
then re-writing that to /members/$2 (this is the leading 2 charactors of 
the nickname) /$1 (where this is the nickname value) and $3 ? this is 
anything after the trailing / after the nickname.

Is that correct?

> This will work for all users with userids of at least 2 characters
> length.
>
> Regards, Hans

Thanks

Dale


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Is mod_rewrite the solution for this...?

Posted by Hans Juergen von Lengerke <le...@sixt.de>.
dale's stuff <st...@colony.net> on Sep 4, 2002:

> An example would be - domain.com/members/greybear/ where I think I should
> create a folder named ./members/gr/greybear/

I'm not entirely sure I understand what you want but maybe this is it:

  RewriteRule ^/members/(([^/]{2})[^/]*)/(.*)$ /members/$2/$1/$3

This will work for all users with userids of at least 2 characters
length.

Regards, Hans


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org