且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

阿帕奇重写规则与RewriteMap指令

更新时间:2023-09-18 23:36:28

在您的地图文件,左侧是关键,右边是值。当您创建一个规则对地图匹配,输入你的关键,它输出的价值。

In your map file, the left side is the key and the right side is the value. When you create a rule for matching against a map, you input the key and it outputs the value.

您重写规则改成这样:

# Put these on one line
RewriteRule ^/section/downloads/([a-zA-Z-]+)/(.*)$
            /blah.php?subsection=${legacy:$1}&title=$2

第一个分组捕获传入URL字符串。在更换$ 1中适用于命名映射。为了使默认值,更改 $ {遗产:$ 1} $ {遗产:$ 1 |未知}

最后,如果你只希望规则上是在映射文件中的值工作,添加一个的RewriteCond

Finally, if you only want the rule to work on values that are in the map file, add a RewriteCond:

RewriteCond ${legacy:$1|Unknown} !Unknown
# Put these on one line
RewriteRule ^/section/downloads/([a-zA-Z-]+)/(.*)$
            /blah.php?subsection=${legacy:$1}&title=$2

条件说,如果地图不返回默认值(未知),然后运行下一个规则。否则,跳过规则,继续前进。

The condition says if the map does not return the default value (Unknown), then run the next rule. Otherwise, skip the rule and move on.

阿帕奇RewriteMap指令