httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Valentin Guggiana <valen...@guggiana.ch>
Subject [users@httpd] Stripping trailing numbers with mod_rewrite
Date Thu, 26 Aug 2004 11:54:41 GMT
Hello

I want to rewrite my URLs depending on username without
trailing numbers, e.g. with REMOTE_USER = user12345 :

/doc/logo.gif  -->  /doc/user/logo.gif


The rewrite rule for user dependency is quite simple and
works well (1):

RewriteCond %{REQUEST_URI} ^/doc/(.*)
RewriteCond %{LA-U:REMOTE_USER} .+
RewriteRule ^/doc/(.*) /doc/%{LA-U:REMOTE_USER}/$1 [NS]

For the above example /doc/logo.gif gets rewritten to
/doc/user12345/logo.gif. Not exactly what I want.


Stripping trailing numbers can easily be done with (2):

RewriteRule ^/doc/(.*)[0-9]/(.*) /doc/$1/$2 [N,NS]

/doc/user12345/logo.gif gets rewritten to /doc/user/logo.gif


But now: how to combine both? The following generates a loop
adding the username serveral times, so it's unusable (3):

RewriteCond %{REQUEST_URI} ^/doc/(.*)
RewriteCond %{LA-U:REMOTE_USER} .+
RewriteRule ^/doc/(.*) /doc/%{LA-U:REMOTE_USER}/$1 [C,NS]
RewriteRule ^/doc/(.*)[0-9]/(.*) /doc/$1/$2 [N,NS]


The next one does not catch the numbers (WHY ?), so it only
does the user dependency (4):

RewriteCond %{REQUEST_URI} ^/doc/(.*)
RewriteCond %{LA-U:REMOTE_USER} .+
RewriteRule ^/doc/(.*) /doc/%{LA-U:REMOTE_USER}/$1 [C,NS]
RewriteRule ^/doc/(.*)([0-9]*)/(.*) /doc/$1/$3 [L,NS]


The only rule set that works for a limited (but adaptable)
length of numbers is (5):

RewriteCond %{REQUEST_URI} ^/doc/(.*)
RewriteCond %{LA-U:REMOTE_USER} .+
RewriteRule ^/doc/(.*) /doc/%{LA-U:REMOTE_USER}/$1 [C,NS]
RewriteRule ^/doc/(.*)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/(.*) /doc/$1/$2 [NS]
RewriteRule ^/doc/(.*)[0-9][0-9][0-9][0-9]/(.*) /doc/$1/$2 [NS]
RewriteRule ^/doc/(.*)[0-9][0-9]/(.*) /doc/$1/$2 [NS]
RewriteRule ^/doc/(.*)[0-9]/(.*) /doc/$1/$2 [L,NS]

It works fine for up to 15 traling numbers. If 7 are enough
one can remove the 4th line.


Is there a better way to do that or can somebody enlight me
why (4) does not work?



Thanks in advance,

Valentin

---------------------------------------------------------------------
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


Mime
View raw message