CakePHP3 url在IIS服务器上重写,而不是从url中删除index.php

I am using CakePHP3 on IIS server first time .

I have translate the .htaccess file into webconfig and put it on the root of my project directory.

After that I am able to access my home page.

Home page :- controller :- Home and action :- index in route.php :-

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

But issue is coming when I try to access the action of other controller example(/cakephp/dashboard/profile) :-

When I try to access profile action of Dashboard controller then it gives me 404 not found error . The same code is working correctly on Linux using .htaccess.

When I add index.php manually after controller(/cakephp/index.php/dashboard/profile) then it is working fine.

Anyone help me how can I fix this issue ?

Here is project directory:- /httpdocs/cakephp/ Under this i have created a web.config file as:-

<?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>

Here is project directory:- /httpdocs/cakephp/ Under this i have created a web.config file as

iis should really be configured to point at the webroot directory, not the directory above it. The web.config then becomes something like:

<?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>