[英]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.