我知道可以匹配一个单词,然后使用其他工具(例如grep -v)反转匹配.但是,我想知道是否可以使用正则表达式匹配不包含特定单词的行(例如hede).
输入:
hoho
hihi
haha
hede
Run Code Online (Sandbox Code Playgroud)
码:
grep "<Regex for 'doesn't contain hede'>" input
Run Code Online (Sandbox Code Playgroud)
期望的输出:
hoho
hihi
haha
Run Code Online (Sandbox Code Playgroud) 我有以下规则,它可以很好地将我的www请求重定向到根目录.
但是我似乎无法将其关闭为localhost.这就是我现在拥有的:
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
我尝试了很多东西,包括:
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^localhost$" negate="true" />
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
你能帮忙吗?正则表达是我的弱点唉
对于SEO优化的原因,我得到了http://Example.com重定向到的所有请求http://www.Example.com.问题是,在本地工作时,请求localhost也会被重定向.
我尝试了这个重写规则中的建议到HTTPS,除非在localhost上回答没有运气.
这是我的实际重定向规则Web.Config(希望它可以帮助那些正在寻找重写规则到WWW的人):
<system.webServer>
<rewrite>
<rules>
<rule name="redirect example.com to www.example.com">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
有帮助吗?