【问题标题】:CakePHP3 url rewrite on IIS server and not removing index.php from urlCakePHP3 url 在 IIS 服务器上重写,而不是从 url 中删除 index.php
【发布时间】:2017-04-17 18:26:44
【问题描述】:

我第一次在 IIS 服务器上使用 CakePHP3。

我已将 .htaccess 文件翻译成 webconfig 并将其放在我的项目目录的根目录下。

之后我就可以访问我的主页了。

主页:- 控制器:- 主页和操作:- route.php 中的索引:-

$routes->connect('/', ['controller' => 'Home', 'action' => 'index', 'index']);

但是当我尝试访问其他控制器example(/cakephp/dashboard/profile) 的操作时,问题来了:-

当我尝试访问仪表板控制器的配置文件操作时,它给了我 404 not found 错误。相同的代码在使用 .htaccess 的 Linux 上也能正常工作。

当我在controller(/cakephp/index.php/dashboard/profile) 之后手动添加 index.php 时,它工作正常。

谁能帮我解决这个问题?

这里是项目目录:- /httpdocs/cakephp/ 在此之下,我创建了一个 web.config 文件:-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
            <rewrite>
              <rules>
                  <clear/>
                <rule name="Exclude direct access to webroot/*" stopProcessing="true">
                    <match url="^webroot/(.*)$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="Rewrite routed access to assets(img, css, files, js, favicon)" stopProcessing="true">
                    <match url="^(img|css|files|js|favicon.ico)(.*)$" />
                    <action type="Rewrite" url="webroot/{R:1}{R:2}" appendQueryString="false" />
                </rule>

                <rule name="Imported Rule 1" stopProcessing="true">
                  <match url="^$" ignoreCase="false" />
                  <action type="Rewrite" url="webroot/" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                  <match url="(.*)" ignoreCase="false" />
                  <action type="Rewrite" url="webroot/{R:1}" />
                </rule>

                  <rule name="Imported Rule 3" stopProcessing="true">
                      <match url="^" ignoreCase="false" />
                      <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="index.php" />
                </rule>
              </rules>
            </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

  • 你好,Shawaz,我也遇到了这个问题,你解决了吗?或者其他人有什么想法吗?

标签: php cakephp iis url-rewriting cakephp-3.0


【解决方案1】:

这是项目目录:- /httpdocs/cakephp/ 在此我创建了一个 web.config 文件

iis 确实应该配置为指向 webroot 目录,而不是它上面的目录。 web.config 然后变成这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
            <rewrite>
              <rules>
                  <clear/>
                <!--- Irrelevant, because webroot/webroot/ doesn't exist
                <rule name="Exclude direct access to webroot/*" stopProcessing="true">
                    <match url="^webroot/(.*)$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                --->
                <!--- Unnecessary, because asset urls directly match asset file paths
                <rule name="Rewrite routed access to assets(img, css, files, js, favicon)" stopProcessing="true">
                    <match url="^(img|css|files|js|favicon.ico)(.*)$" />
                    <action type="Rewrite" url="webroot/{R:1}{R:2}" appendQueryString="false" />
                </rule>
                --->
                <!--- No exceptions necessary
                <rule name="Imported Rule 1" stopProcessing="true">
                  <match url="^$" ignoreCase="false" />
                  <action type="Rewrite" url="webroot/" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                  <match url="(.*)" ignoreCase="false" />
                  <action type="Rewrite" url="webroot/{R:1}" />
                </rule>
                --->

                  <rule name="Imported Rule 3" stopProcessing="true">
                      <match url="^" ignoreCase="false" />
                      <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="index.php" />
                </rule>
              </rules>
            </rewrite>
    </system.webServer>
</configuration>

【讨论】:

    猜你喜欢
    • 2015-06-24
    • 2017-12-21
    • 2014-05-06
    • 2018-08-22
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多