首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的IIS 7重写规则不起作用?

为什么我的IIS 7重写规则不起作用?
EN

Stack Overflow用户
提问于 2011-06-13 17:43:48
回答 1查看 2.2K关注 0票数 0

我已经将Linux下的Wordpress Mu博客迁移到了IIS7下的WP3,所以我需要将http://mydomain.com/blog/blahblah/重定向到http://mydomain.com/blahblah/

我添加到wordpress web.config

代码语言:javascript
运行
复制
        <rule name="rewrite /blog/">
            <match url="^/blog/([_0-9a-z-]+)/" />
            <conditions>                
            </conditions>
            <action type="Rewrite" url="/{R:1}/" />
        </rule>

因此,web.config现在包含:

代码语言:javascript
运行
复制
<?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/不会被重定向。为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-13 17:59:34

1)最好将此规则移到通配符规则之上

2)你有前导斜杠^/blog/... --你不需要它:^blog/...

3)因为没有使用任何条件,所以我也删除了<conditions></conditions>

代码语言:javascript
运行
复制
<rule name="rewrite /blog/">
    <match url="^blog/([_0-9a-zA-Z\-]+)/$"/>
    <action type="Rewrite" url="/{R:1}/"/>
</rule>

上面是重写规则--您在浏览器中看到相同的url,但在它后面执行的方式不同。

如果您想要重定向,请使用以下命令:

代码语言:javascript
运行
复制
<rule name="rewrite /blog/">
    <match url="^blog/([_0-9a-zA-Z\-]+)/$"/>
    <action type="Redirect" url="/{R:1}/" redirectType="Permanent" />
</rule>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6328816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档