![](/img/trans.png)
[英]How can I get the URL of an <a href=“http://www.mysite.com”> in JavaScript?
[英]How to correctly rewrite only mysite.com to www.mysite.com and nothing else?
這是Web.config中將裸域重定向到www的部分。
<system.webServer>
<rewrite>
<rules>
<clear/>
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\."/>
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
問題在於,它還會在其他任何地址前面添加“ www”,例如:
我只需要重定向mysite.com即可。 如何修改規則?
我認為您想得太多了。 我不能測試,但最簡單的方法似乎正在改變你的條件, 只是匹配要重新寫的名字。
<add input="{HTTP_HOST}" negate="false" pattern="^mysite.com$"/>`?
嘗試更改此行:
<add input="{HTTP_HOST}" negate="false" pattern="^mysite.com$"/>
如果pattern
是正則表達式,則可以使用
^[^\.]\.[^\.]$
僅重定向不帶子域的請求(僅包含一個點)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.