匹配不以.html结尾的字符串 [英] Matching strings not ending with .html
问题描述
我想在我们的网站用户点击没有尾部斜线的REST路径时重定向。
I want to redirect my website users when they hit a REST path without the trailing slash.
示例。
http://mywebsite.my/it/products/brand/name => http://mywebsite.my/it/products/brand/name/
http://mywebsite.my/it/products => http://mywebsite.my/it/products/
http://mywebsite.my => http://mywebsite.my/
http://mywebsite.my/it/products/brand/name/code.html => ???
嗯,我不希望最后一个被重写,我不想要尾随当URL以 .html 结尾时斜杠。
Well, I don't want the last one to be rewritten, I don't want the trailing slash when the URL ends with .html.
我正在使用IIS7的URL重写模块,这是我的斜杠规则 。
I'm working with URL rewrite module of IIS7, and this is my "slash-rule".
<rule name="SLASHFINALE" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
换句话说,如果输入网址与该正则表达式匹配(一切不以斜杠结尾),我重写了添加尾部斜杠的相同URL。
In other words, if the input url matches that regex (everything not ending with a slash), I rewrite the same URL adding the trailing slash.
所以我的规则是相同的,但只需添加一点:重写所有URL,除了那些(已经)有尾部斜线或以结尾的那些。html。
So my rule would be the same, but with that little addition: rewrite all URLs, except the ones (already) having the trailing slash or the ones ending with ".html".
我写了这个
(.*(?<!html)[^\/])$
但我不明白为什么它不起作用。
but I can't understand why it's not working.
推荐答案
IIS Javascript风格的正则表达式解析器不支持条件表达式。
IIS Javascript-flavored regex parser does not support conditional expressions.
我最终得到了这个:
<match url="(.*[^\.]...[^\/]$)" />
足够我。
这篇关于匹配不以.html结尾的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!