我已经将Linux下的Wordpress Mu博客迁移到了IIS7下的WP3,所以我需要将http://mydomain.com/blog/blahblah/重定向到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/不会被重定向。为什么?
发布于 2011-06-13 17:59:34
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>https://stackoverflow.com/questions/6328816
复制相似问题