错误404将.htaccess转换为web.config

时间:2018-08-21 15:57:18

标签: php .htaccess iis web-config

我的Web服务器是IIS,因此我的.htaccess文件不起作用。您能帮我重定向和隐藏文件扩展名吗? 我的代码收到404错误。 我有两个web.config文件。

原始的.htaccess(1):

Options -MultiViews
RewriteEngine On
Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

web.config(1):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RewritePHP" stopProcessing="true">
      <match url="^(.+)$" />
      <action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true"/>
    </rule>
  </rules>
</rewrite>
 </system.webServer>
</configuration>

原始.htaccess(2):

RewriteEngine on
RewriteRule ^(.*) public/$1 [L]

此web.config(2)运行良好(将虚拟主机路由到/ public):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
<rewrite>
  <rules>
    <rule name="rewritepublic" stopProcessing="true">
      <match url="^(.*)" />
      <action type="Rewrite" url="public/{R:1}" />
    </rule>
  </rules>
</rewrite>
  </system.webServer>
</configuration>

详细信息错误404:

IIS Web Core
MapRequestHandler
StaticFile
0x80070002

URL request: http://localhost:81/site/public/page1
Path: C:\inetpub\wwwroot\site\public\page1

0 个答案:

没有答案