Forum Moderators: phranque

Message Too Old, No Replies

Combining many RewriteRules into one

Need to know if it's possible

         

twist

9:50 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I only have the first 4 levels shown here, but I need to go 7 vars deep, i.e. v7=$7

RewriteRule ^([a-z]+)/([a-z0-9]+)/([a-z0-9]+)/([a-z0-9_]+)$ /page.php?v1=$1&v2=$2&v3=$3&v4=$4 [L]
RewriteRule ^([a-z]+)/([a-z0-9]+)/([a-z0-9]+)$ /page.php?v1=$1&v2=$2&v3=$3 [L]
RewriteRule ^([a-z]+)/([a-z0-9]+)$ /page.php?v1=$1&v2=$2 [L]
RewriteRule ^([a-z]+)$ /page.php?v1=$1 [L]

I am just hoping their is a way to combine all these into one simple rewrite rule. If need be, I could make all levels ([a-z0-9_]+) if thats helps in combining them all into one RewriteRule.

One more question,

If it is possible to combine the above into one line, is it possible to also add this line to the mix,

RewriteRule ^(search)$ /page.php?v1=$1 [QSA,L]

I need QSA for this and only this one rewriterule, is it a bad idea to add QSA to rewriterules that don't need it?

jdMorgan

10:13 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't really answer your question, since I don't know how your URLs, directories, and files are arranged. You can try the following; If it doesn't work, then it doesn't work...

RewriteRule ^search$ /page.php?v1=search [QSA,L]
RewriteRule ^([a-z]+)/?([a-z0-9]*)/?([a-z0-9]*)/?([^a-z0-9]*)$ /page.php?v1=$1&v2=$2&v3=$3&v4=$4 [L]

If you request yourdomain/foo, the result will be yourdomain/page.php?v1=foo&v2=&v3=&v4=

If your script can't handle the blank vars, then it won't work.

Replace all broken pipe "¦" characters with solid pipes before use.

Jim

twist

2:27 am on Feb 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your good Jim, worked like a charm. Thank you so much for your help.