Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite (again)

How to simplify a couple of rewriterules

         

thijsnetwork

11:59 am on Apr 13, 2004 (gmt 0)

10+ Year Member



Hi!

I was wondering if it's possible to simplify these 3 rules into 1:


RewriteRule ^([A-Za-z0-9_]+)/?$ index.php?mod=blog&user=$1 [T=application/x-httpd-php,L]
RewriteRule ^([A-Za-z0-9_]+)/([0-9]+)/?$ index.php?mod=blog&user=$1&pg=$2 [T=application/x-httpd-php,L]
RewriteRule ^([A-Za-z0-9_]+)/([0-9]+)/(private¦all)/?$ index.php?mod=blog&user=$1&pg=$2&view=$3 [T=application/x-httpd-php,L]

Anybody?

jdMorgan

2:43 pm on Apr 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your script can accept blank parameters, such as "page=&view=", and if the parameters always appear in the same order in the static (requested) URL, then you could use only the last rule, with a "?" added to the subpatterns to make them otional:
RewriteRule ^([A-Za-z0-9_]+)/([0-9]+/)?(private¦all)?/?$ index.php?mod=blog&user=$1&pg=$2&view=$3 [T=application/x-httpd-php,L]
Otherwise, what you've already got is a good method.

Jim

thijsnetwork

5:49 pm on Apr 13, 2004 (gmt 0)

10+ Year Member



no, it doesn't work the same as my first post as you said, so the new line cannot replace the old 3 unfortunately, because i do need the functionality of the 3 lines in the first post.