Forum Moderators: phranque

Message Too Old, No Replies

General RewriteRule for many undefined parameters in URL

         

FedericoBiccheddu

10:47 am on Apr 17, 2010 (gmt 0)

10+ Year Member



I'm trying to write a rule to make that one can generalize, since multiple pages to pass the values are different. Right now I could do:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^forum/([^/]{1,255})/([a-z]+)([:]{1})([a-zA-Z0-9]+)viewforum.php?name=$1&$2=$4&%1 [L]


To address such as:
Nome+del+Forum/+/page:1/action:do


Should return:
forum.php?name=Nome+del+Forum&page=1&action=do


Instead, take only the first parameter (in this case page=1):
forum.php?name=Nome+del+Forum&page=1


How can I fix? Thanks in advance!

jdMorgan

12:58 am on Apr 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The rule and the example above are inconsistent, so here's a consistent example that you should be able to modify slightly to suit your needs:

# Rewrite /forum/Nome+del+Forum/+/page:1/action:do to /forum.php?name=Nome+del+Forum&page=1&action=do
# including any existing query parameters
RewriteRule ^forum/([^/]+)/\+/([a-z]+):([a-zA-Z0-9]+)$ /forum.php?name=$1&$2=$3 [QSA,L]

Jim

FedericoBiccheddu

1:11 am on Apr 18, 2010 (gmt 0)

10+ Year Member



Thanks for the reply, but does not work! I would take a general rule that a numvero undefined values.
Must work with:
Nome+del+Forum/+/page:1/action:do

with:
Nome+del+Forum/+/hash:as74c4sn3/view:unread/key:value

or with:
Nome+del+Forum/+/mark:read

g1smd

8:17 am on Apr 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe you need several separate rules, one for each 'pattern'?

FedericoBiccheddu

11:58 am on Apr 18, 2010 (gmt 0)

10+ Year Member



I would avoid just that! To write a rule that limits the values passed via GET! Suppose a user does a search engine, there are many options to take via GET, you can write a new rule if it has 10 options!

jdMorgan

3:49 pm on Apr 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mod_rewrite is not a high-level scripting language, so other than writing specific case-by-case rules, there is no mod_rewrite solution to this problem.

Consider rewriting all requests that "look like" these to a script, which can use recursive routines and database lookups to generate the correct result.

Jim