gpt4 book ai didi

yii2 - 如何在 IIS 上正确配置 web.config 以发布 YII2 Advanced

转载 作者:行者123 更新时间:2023-12-05 06:35:49 25 4
gpt4 key购买 nike

我正在安装一个基于 YII2 高级主题的应用程序。它在 Apache 上运行良好,但在 IIS 7 上安装时,漂亮的 url 会非常糟糕,我正在使用以下 web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rewriteMaps" overrideModeDefault="Allow" />
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>

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

但是这个是行不通的,因为当打开一个特定的路由时,它会尝试去那个路由而不是在 YII2 中构建正确的路由。

这个问题在抛出的error上可以看出,可以看到它试图打开物理路径\web\user\login,这显然不存在。什么时候它应该打开像 .../index.php?r=controller/action

这样的东西

enter image description here

在 apache 上我会使用:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

任何可以帮助我解决这个问题的想法。

最佳答案

经过几天的搜索并试图理解为什么 dos 不起作用。运气不太好。

终于找到了。

首先:
确保您已经在 IIS7 上安装了 URL Rewrite。

如果您有 web.config 配置,并且它仍然路由到物理目录而不是 Controller /操作路由,则几乎 100% 意味着您缺少 URL Rewrite。是的,这是一个不一定安装的插件。

所以继续吧,从URL Rewrite下载并安装它到你的国际空间站上

enter image description here

第二:
这是实际工作的 web.config。请注意,我以:match url=".*" 结尾,还请注意我添加了一行来处理图像和其他静态内容。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rewriteMaps" overrideModeDefault="Allow" />
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
<system.webServer>
<rewrite>
<rules>
<rule name="Yii2 Routing that works" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

最后如果您使用的是 YII2 高级主题,请确保在两个 Web 目录中更新和配置您的 web.config。

这个 menas,你需要戴上它们:
C:\webroot****\www\backend\web\web.config
C:\webroot****\www\frontend\web\web.config

并且一定要更新你的 main.php «or config.php on basic»在高级上,您需要确保您的 enablePrtettyUrl 已针对前端和后端进行配置:

C:\webroot****\www\backend\config\main.php
C:\webroot****\www\frontend\config\main.php

'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
...
]

我仍在调试并尝试解决一些小问题,如果我发现其他问题,我会更新 os。

关于yii2 - 如何在 IIS 上正确配置 web.config 以发布 YII2 Advanced,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49494959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com