繁体   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