簡體   English   中英

將URL重寫為index.php,並在IIS7上使用web.config刪除.php擴展名

[英]URL rewrite to index.php and remove .php extension with web.config on IIS7

我想實現以下目標-

  1. 將所有請求重定向到index.php頁面。
  2. 想要從網址中隱藏.php,但是我的網頁也應該可以使用.php擴展名訪問。
  3. 應該加載圖片,css,js文件。
  4. 在某些情況下,我還看到了無限循環。 如何避免這種情況?

我在web.config和point#1&3下面使用正常,但在point#2上有問題。 它隱藏了.php,但是當我在URL中添加.php時卻給出了500個內部服務器錯誤,當我在表單動作中添加.php時也給出了500個內部錯誤。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <clear/>
        <add value="index.php" />
        <add value="default.html" />
      </files>
    </defaultDocument>
    <security>
      <authentication>
        <basicAuthentication enabled="true" />
      </authentication>
    </security>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/test.html" responseMode="ExecuteURL" />
    </httpErrors>


    <rewrite>
      <rules>

        <rule name="RewritePHP">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="?path={R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
<rewrite>
        <rules>
            <rule name="Imported Rule 1" 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM