[英]Why my IIS 7 rewrite rule doesn't work?
I have migrated a Wordpress Mu blog under Linux to WP 3 under IIS 7 so I need to redirect http://mydomain.com/blog/blahblah/ to http://mydomain.com/blahblah/
我添加到 wordpress web.config
<rule name="rewrite /blog/">
<match url="^/blog/([_0-9a-z-]+)/" />
<conditions>
</conditions>
<action type="Rewrite" url="/{R:1}/" />
</rule>
這樣 web.config 現在包含:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
<rule name="rewrite /blog/">
<match url="^/blog/([_0-9a-z-]+)/" />
<conditions>
</conditions>
<action type="Rewrite" url="/{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Wordpress 繼續工作,但 /blog/ 未重定向。 為什么?
1)最好將此規則移到通配符規則之上
2)你有前導斜杠^/blog/...
- 你不需要它: ^blog/...
3)因為沒有使用條件,我也刪除了<conditions></conditions>
<rule name="rewrite /blog/">
<match url="^blog/([_0-9a-zA-Z\-]+)/$"/>
<action type="Rewrite" url="/{R:1}/"/>
</rule>
以上是重寫規則——你在瀏覽器中看到相同的 url 但后面的執行方式不同。
如果要重定向,請使用以下命令:
<rule name="rewrite /blog/">
<match url="^blog/([_0-9a-zA-Z\-]+)/$"/>
<action type="Redirect" url="/{R:1}/" redirectType="Permanent" />
</rule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.