2017-10-28 353 views
0

我堅持重寫和重定向規則webconfig。 我想刪除文件擴展名並在URL末尾強制添加尾部斜槓我得到了一段代碼,但它與文件擴展名一起工作,當我使用隱藏文件擴展名的相同代碼時,它將我帶到404頁面。 僅供參考 - http://example.com/about-us.php/工作正常web.config:隱藏文件擴展名並強制在URL末尾添加尾部斜槓

預期的結果 - http://example.com/about-us/重定向到404頁。

請告訴我隱藏文件擴展名的代碼,並使用web.config文件同時添加尾部斜線。

我已經應用了,下面我列出了一些規則,斜線增加,但它帶我到http://example.com/about-us.php/當我進入瀏覽器

http://example.com/about-us僅供參考 - 這是工作的罰款與http://example.com/about-us/但我想http://example.com/about-us網址http://example.com/about-us/

這裏是我的規則列表:

<system.webServer> 
    <httpErrors errorMode="Custom"><!-- For non-managed files --> 
     <remove statusCode="404" subStatusCode="-1" /> 
     <error statusCode="404" path="/404.php" responseMode="ExecuteURL" /> 
    </httpErrors> 
<rewrite> 
    <rules> 

     <rule name="Add trailing slash rule 1" stopProcessing="true"> 
      <match url="(.*[^/])$" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      </conditions> 
      <action type="Redirect" redirectType="Permanent" url="{R:1}.php/" /> 
     </rule> 
     <rule name="Add trailing slash rule 2" stopProcessing="true"> 
      <match url="(.*[^/])" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="{R:1}.php/" redirectType="Permanent" /> 
     </rule> 
     <rule name="hide php extension" stopProcessing="true"> 
      <match url="^(.*)$" /> 
      <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
       <add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" /> 
      </conditions> 
      <action type="Rewrite" url="{R:1}.php/" /> 
     </rule> 
    </rules> 
</rewrite> 
</system.webServer> 
+1

能否請您添加規則,你試過嗎? –

回答

1

您需要使用這個規則:

<rules> 
    <rule name="AddTrailingSlashRule" stopProcessing="true"> 
     <match url="(.*[^/])$" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="{R:1}/" /> 
    </rule> 

    <rule name="hide php extension" stopProcessing="true"> 
     <match url="^(.*)/$" /> 
     <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="{R:1}.php" /> 
    </rule> 
</rules> 
+0

它適用於我。謝謝 – Sachin

相關問題