douhuan1908 2016-12-02 18:48
浏览 41

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>
  • 写回答

1条回答 默认 最新

  • dpa31905 2016-12-12 15:40
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真