2011-06-13 72 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