Forum Moderators: phranque

Message Too Old, No Replies

amount of URL parameters and mod_rewrite

Variable amount of parameters at URL and mod_rewrite

         

zaldun

7:22 pm on May 8, 2006 (gmt 0)

10+ Year Member



Hi all!

I am new here, and i would like to know your opinion about next case:

i have been searching for the topic (internet and site), and unable to find anything directly related to the problem;

maybe it is not possible using Apache's mod_rewrite (though i found a page related to ISAPI rewrite which allows to); it is about how to get kind of generic URL rewriting rule, for an extensible ( or varying) amount of URL parameters (even placed before the script name, the script name would 'act' as the identifier for the rule);

the idea is for a site which may set a rewrite setting ON or OFF in admin settings, and according to that, generate programatically URLs of the public area in SE friendly way (or not); the site would work with accounts areas, and also have a global area; and there is a search feature, which may work in account area, or globally; so, the URL 'regular expression' could lool like (it is not exactly the reg. exp. just explanation):

www.host.tld(/account_name)?/search(/(keyword)+)?(/page)?(/items_per_page)?

or maybe, a bit larger URL, but identifying each kind of URL parameter ( except the account name):
www.host.tld(/account_name)?/search(/keywords/(a-zA-Z0-9\+)+)?(/page/(0-9)+)?(/perpage/(0-9)+)?

so we may get a URL like: www.host.tld/search/keywords/php+mysql
and this would make a global search on all accounts on the keywords of php and mysql; and would be rewriten to:
www.host.tld/search.php?keywords=php+mysql
but if i use a URL like:
www.host.tld/account1/search/keywords/php+mysql
then:
www.host.tld/search.php?account=account1&keywords=php+mysql

and URl parameters like 'page', 'items per page' are optional ...;
or maybe a user tries to temper URL and remove keywords ...

well so the question is if there isnt a generic way, using URL rewriting, of reading the part about URL parameters to the right of script name: var1/foo1/var2/foo2/var3/foo3 ...
and rewrite URL like: var1=foo1&var2=foo2&var3=foo3...

and then at PHP i take care of which paramters where passed, and about sanitize the stuff ...;

currently i have to write diferent versions of rule, according if there is account string before script name ( though i may move that to the right of script name ...if rules get easier that way), and according to each parameter that may appear after the script name ..( also think if later it is needed to enhance the script and adding new URL parameters ...);

All above could be done quite easily through PHP, but i would like to know if there is way to make like a loop on var name, var value pairs .. and rewrite them

Sorry for long post, and thanks in advance for your comments, ideas, ..

Ibon