首页 > 解决方案 > 如何在 Rewrite_Map 中允许特殊字符?

问题描述

这是我正在使用的配置

RewriteEngine on
RewriteMap shortlinks txt:/var/www/html/s.overhash.net/public_html/shortlinks.txt
RewriteRule ^/(.+)$ ${shortlinks:$1} [R=temp,L]

我的 txt 文档看起来像这样:

9H40o https://osyrisrblx.github.io/playground/#code/HYUw7gBAggTjCGBPAPMArgWwEYhgPgAoBKAOhhABM0BjEAggB3IDcAaCatOEYAFyIC8eJiGYBqAZ258iQA

但是,在访问我的网站 ( http://s.overhash.net/9H40o ) 时,它会将 %23 替换为#%23,从而使 URL 变为:

https://osyrisrblx.github.io/playground/%23code/HYUw7gBAggTjCGBPAPMArgWwEYhgPgAoBKAOhhABM0BjEAggB3IDcAaCatOEYAFyIC8eJiGYBqAZ258iQA

(这是无效的)

我将如何确保#遗体?

标签: apacheapache2url-shortener

解决方案


这不是重写映射问题,而是重写规则的工作方式。默认情况下,特殊字符将被转义。

NE如果您不希望发生这种情况,请在重写中使用该标志:

RewriteRule ^/(.+)$ ${shortlinks:$1} [NE,R=temp,L]

有关https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne的更多详细信息


推荐阅读