gpt4 book ai didi

regex - 使用 Tuckey URL Rewrite 添加文件扩展名

转载 作者:行者123 更新时间:2023-11-28 22:55:37 24 4
gpt4 key购买 nike

我正在使用 tuckey url 重写过滤器,我想将语言扩展名 (.cfm) 添加到干净的 url。 (我知道我假设路径中的最后一个词始终是脚本。)

比如我想把.cfm加到

/someScript
/module/employee/anotherScript

并且显然不是已经具有扩展名的路径(定义为具有句点)

/someScript.cfm
/module/employee/anotherScript.cfm

这是我想到的正则表达式规则:

<rule>
<from>^((?!\.)[\w/])*$</from>
<to type="redirect" last="true" qsappend="true">$0.cfm</to>
</rule>

问题来了。我还想允许一个可选的尾部斜杠,以便删除斜杠并添加文件扩展名。

/someScript/
/module/employee/anotherScript/

如何重写我的正则表达式规则以忽略可选的尾部斜线?

最佳答案

^((?:(?!\.)[\w\/])*?)\/?$

试试这个。查看演示。替换为 $1.cfm

https://regex101.com/r/fA6wE2/6

关于regex - 使用 Tuckey URL Rewrite 添加文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27920218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com