Thread URL auf Querystring abbilden (1 answers)
Opened by GwenDragon at 2019-10-01 12:56

GwenDragon
 2019-10-01 14:52
#190605 #190605
User since
2005-01-17
14533 Artikel
Admin1
[Homepage]
user image
Oh, was war ich da verschnarcht.

Einfach [B] mit nutzen und der Querystring wird vor veränderung bei einem Rewrite geschützt.

https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b
B (escape backreferences)

The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation.

mod_rewrite has to unescape URLs before mapping them, so backreferences will be unescaped at the time they are applied. Using the B flag, non-alphanumeric characters in backreferences will be escaped. For example, consider the rule:

RewriteRule ^search/(.*)$ /search.php?term=$1

Given a search term of 'x & y/z', a browser will encode it as 'x%20%26%20y%2Fz', making the request 'search/x%20%26%20y%2Fz'. Without the B flag, this rewrite rule will map to 'search.php?term=x & y/z', which isn't a valid URL, and so would be encoded as search.php?term=x%20&y%2Fz=, which is not what was intended.

With the B flag set on this same rule, the parameters are re-encoded before being passed on to the output URL, resulting in a correct mapping to /search.php?term=x%20%26%20y%2Fz.

Note that you may also need to set AllowEncodedSlashes to On to get this particular example to work, as httpd does not allow encoded slashes in URLs, and returns a 404 if it sees one.

This escaping is particularly necessary in a proxy situation, when the backend may break if presented with an unescaped URL.



Damit muss das Rewrite also so sein:
RewriteRule ^ttt/tags/(.*) /cgi-bin/t1.pl?-tags=$1 [B,L]

Wirk vielleicht auch mal anderen helfen, die verschnarcht, ohne genügend Kaffee arbeiteten.
Last edited: 2019-10-01 14:54:02 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread URL auf Querystring abbilden