我第一次在IIS服务器上使用CakePHP3。
我已将.htaccess文件翻译成webconfig并将其放在项目目录的根目录下。
之后我可以访问我的主页。
主页: - 控制器: - 主页和操作: - route.php中的索引: -
$routes->connect('/', ['controller' => 'Home', 'action' => 'index', 'index']);
但是当我尝试访问其他控制器example(/cakephp/dashboard/profile)
的操作时,问题就出现了: -
当我尝试访问Dashboard控制器的配置文件操作时,它会给我404找不到错误。使用.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>
答案 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>