2011-06-13 73 views
0

我已经迁移Linux下一个WordPress博客沐向WP 3 IIS 7下,所以我需要重定向到http://mydomain.com/blog/blahblah/http://mydomain.com/blahblah/为什么我的IIS 7重写规则不起作用?

我加入到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的继续工作,但/博客/没有重定向。为什么?

回答

3

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> 
+0

我复制并粘贴到web.config中,但仍然重定向不会发生:错误404 – user310291 2011-06-13 11:14:17

+0

我已经更新了我的答案 - 请 – LazyOne 2011-06-13 11:26:25

+0

嗯,好的,谢谢我不知道其中的差异,但现在它的作品:) – user310291 2011-06-13 13:06:30