[英]Symfony2 - How can I remove 'web/app_dev.php/' from my url?
How can I remove 'web/app_dev.php/' from my url when I want my symfony website to go live? 当我希望我的symfony网站上线时,如何从我的网址中删除“web / app_dev.php /”?
This is the default url during development, 这是开发期间的默认URL,
http://{localhost}/my-symfony-2/web/app_dev.php/hello/World
So when I go live, I would like to be able to use this url to access my symfony website, 因此,当我上线时,我希望能够使用此网址访问我的symfony网站,
http://my-symfony-2.com/hello/World
Any ideas? 有任何想法吗?
To hide app.php
you need to: 要隐藏app.php
您需要:
mod_rewrite
module installed and enabled in Apache looking the phpinfo()
under "apache2handler" ---> "Loaded Modules" directory (you should have that possibility directly through the control panel). 检查你是否在Apache中安装并启用了mod_rewrite
模块,在“apache2handler”--->“Loaded Modules”目录下查找phpinfo()
(你应该直接通过控制面板获得这种可能性)。 After these checks you have to: 完成这些检查后,您必须:
NOTE : Symfony2 already comes with an .htaccess
file stored in the default web directory but if you don't know what are you doing it's better to replace the directives containet within the "IfModule mod_rewrite.c" with those shown below. 注意 :Symfony2已经附带了一个存储在默认Web目录中的.htaccess
文件,但如果您不知道自己在做什么,最好将“IfModule mod_rewrite.c”中的指令containet替换为如下所示。
Use the native Symfony2 .htaccess
or create a new one file with the .htaccess
extension and copy/paste inside these directives to hide app.php
in production (not on localhost): 使用本机Symfony2 .htaccess
或创建一个带有.htaccess
扩展名的新文件,并在这些指令中复制/粘贴以隐藏生产中的app.php
(不在localhost上):
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^app\\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L] RewriteRule .? - [L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.*)$ app.php [QSA,L] RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\\2$ RewriteRule ^(.*) - [E=BASE:%1] RewriteRule .? %{ENV:BASE}app.php [L] </IfModule> # and from the symfony's original <IfModule !mod_rewrite.c> <IfModule mod_alias.c> # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. RedirectMatch 302 ^/$ /app.php/ # RedirectTemp cannot be used instead </IfModule> </IfModule>
To apply the modifications you need to restart Apache (also this is usually did on the control panel of your web space). 要应用修改,您需要重新启动Apache(这通常在您的Web空间的控制面板上执行)。
Googling a bit you can find tons of examples and tutorials but to start to learn take a look at this simple .htaccess guide with many useful infos and examples and the Official URL Rewriting Guide (Apache2.4) . 谷歌搜索有点你可以找到大量的例子和教程,但要开始学习,看看这个简单的.htaccess指南与许多有用的信息和例子和官方URL重写指南(Apache2.4) 。 If you encounter some problem update your post adding all related infos otherwise you can make another question here on SO. 如果你遇到一些问题更新你的帖子添加所有相关的信息,否则你可以在这里提出另一个问题。
If you have access to the deployment server, from terminal you can use: php app/console cache:clear --env=prod
and this will clear the prod cache and you will be able to use the standard route. 如果您有权访问部署服务器,则可以使用: php app/console cache:clear --env=prod
,这将清除prod缓存,您将能够使用标准路由。
But if you are deploying the application on hosting where you haven't access to terminal, need to find the app/cache/*
and app/logs/*
and remove their content and after add the proper rights (766|777) for the folders. 但是,如果您要在无法访问终端的托管上部署应用程序,则需要找到app/cache/*
和app/logs/*
并删除其内容,并在添加适当的权限(766 | 777)之后文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.