从 url 中删除 web/app_dev.php/ [英] Remove web/app_dev.php/ from url

查看:22
本文介绍了从 url 中删除 web/app_dev.php/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 symfony 2 中的应用程序已经完成.
现在我想从 url 中删除 web/app_dev.php/.

I have my application in symfony 2 done.
And now I want to remove the web/app_dev.php/ from the url.

我读到了这个,然后做了这个:

I read about this and after doing this:

php app/console cache:clear --env=prod --no-debug

并添加.htaccess:

And add .htaccess:

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

此后我可以使用 url: localhost/test/web/但这不完全是我的目标.我也想删除网络.

After this I can use the url: localhost/test/web/ But it's not exactly my goal. I want to remove the web also.

在此之后还有另一个问题.当我使用 localhost/test/web/访问页面时,缺少一些样式表,但在 app_dev.php 中,一切看起来都不错.

And after this there's another problem. When I'm using localhost/test/web/ to access the page there's some stylesheet missing, but in app_dev.php everything looks good.

我的问题是,如何从 url 中删除/web/?我怎么能缺少样式表?

My question is, How can I remove the /web/ from the url? And how can I have the stylesheet missing?

推荐答案

Apache/mod_rewrite 配置

要删除/web部分,您可以另外设置RewriteBase

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /web/
    ...

... 或将您的 DocumentRoot 直接设置为 apache VirtualHost 配置中的 web 文件夹.

... or set your DocumentRoot directly to the web folder in your apache VirtualHost configuration.

prod 环境中缺少的样式表可以通过调用 assets:install 命令来解决.

The missing stylesheet in the prod environment can be resolved by invoking the assets:install command.

dev 中,symfony 将直接从包的 Resources/public 文件夹中提供文件,因为默认的 config_dev.yml 包含 assetic.use_controller:真.

In the dev symfony will serve the files directly from the bundle's Resources/public folders because the default config_dev.yml contains assetic.use_controller: true.

出于性能原因,默认生产配置具有 assetic.use_controller: false.资产不会在每次请求时都通过 symfony 重新编译和提供服务.

The default production configuration has assetic.use_controller: false for performance reasons. Assets will not be recompiled and served through symfony on every request.

现在,包的 Resource 文件夹中的资产无法访问,除非它们被移动/符号链接到 web 文件夹,您的网络服务器可以在该文件夹中找到 assets:installassetic:dump 命令执行.

Now the assets in a bundle's Resource folder are not accessible until they are being moved/symlinked to the web folder where your webserver can find them which the assets:install and assetic:dump commands do.

这篇关于从 url 中删除 web/app_dev.php/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆