当部署到测试服务器时,我无法访问公用文件夹中的任何内容。我收到Symfony Route错误。好像它无法识别公用文件夹。所有页面正确路由。我的开发环境是以下c:\ inetpub \ wwroot \ userdir \ symfony-test 转换为此URL。 https://servername/userdir/symfony-test/test
尝试拉出下面的测试图像或树枝中的css或js文件时出现404错误
<img src="{{ asset('build/images/test.jpg') }}" alt="test">
看到没有得到完整路径,我将framwork.yaml更改为设置提供完整路径的base_urls,然后设置了json manifest_path。虽然清单文件路径正确无误,但我可以看到它提供了使用base_urls的完整路径,但对于公用文件夹中的任何内容,我仍然会得到404。
assets:
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
base_urls:
- 'https://servername/userdir/symfony-test/public/'
进行上述操作会导致
GET https://servername/userdir/symfony-test/build/images/test.93d146a7.jpg 404 (Not Found)
我还按照下面的链接说明,如下更新了composer.json文件,以将public-dir添加到“额外”下。 https://symfony.com/doc/current/configuration/override_dir_structure.html
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
"public-dir": "userdir/symfony-test/public/"
}
使用encore webpack编译文件并按预期工作。
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
.enableVersioning()
// public path used by the web server to access the output path
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.addEntry('test','./assets/images/test.jpg')
这也可能是有用的信息。
这是/public/web.config文件中的规则。
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
symfony-test / web.config中的规则
<rewrite>
<rules>
<rule name="Symfony4" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
在IIS Windows Server 2012 R2上运行Symfony 4。
PHP 7.2.13,
作曲者1.6.5版,
节点版本8.11.4,
纱线1.9.4
我如何才能识别公用文件夹而不将其视为路由或收到404。
答案 0 :(得分:0)
我发现有人在github上为symfony 2设置了iis环境。考虑了目录结构之后,我将这些规则添加到了我的web.config文件中,现在它可以按预期运行。希望这对出于任何原因想要在iis上使用symfony的其他人有所帮助:
<rules>
<rule name="TempRewriteToWeb" stopProcessing="false">
<match url="^(public/)?(.*)$" />
<action type="Rewrite" url="public/{R:2}" logRewrittenUrl="true" />
</rule>
<rule name="StaticFiles" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="{R:0}" logRewrittenUrl="true" />
</rule>
<rule name="RewriteRequestsToPublic" stopProcessing="true">
<match url="^(public/)(.*)$" />
<action type="Rewrite" url="public/index.php?{R:2}" logRewrittenUrl="true"/>
</rule>
</rules>