简体   繁体   English

Symfony2 - 如何从我的网址中删除“web / app_dev.php /”?

[英]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您需要:

  1. having access at least to the web root of your site. 至少可以访问您网站的网站根目录。 Usually on the control panel of your web hosting space you can find from which you can upload your files (or if you have the access credentials you can install and use a Free FTP client like Filezilla ). 通常在您的Web托管空间的控制面板上,您可以找到可以从中上载文件的文件(或者如果您具有访问凭据,则可以安装和使用Filezilla等免费FTP客户端)。
  2. checking if you have the 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替换为如下所示。

  1. 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.

相关问题 如何从Symfony2 URL中删除“web / app_dev.php”? - How to remove “web/app_dev.php” from Symfony2 URLs? Symfony2如何缓存我的文件app_dev.php - how Symfony2 cache my file app_dev.php .htacess正在进入主页,但未进入子页面,因此,如何从Symfony2 URL中删除“ web / app_dev.php”? - .htacess is working into the home page but not working into the sub pages so, How to remove “web/app_dev.php” from Symfony2 URLs? 从网址中删除/web/app_dev.php - Remove /web/app_dev.php from url 从Symfony2中的开发(app_dev.php)到生产(app.php) - From development (app_dev.php) to production (app.php) in Symfony2 Symfony2:在 app.php 和 app_dev.php 之间切换,我这样做对吗? - Symfony2 : Switching between app.php and app_dev.php, am I doing it right? Symfony2无法访问app_dev.php,除非删除Web文件夹中的.htacess文件 - Symfony2 cant access app_dev.php unless removing .htacess file in web folder Symfony2:app_dev.php只允许访问IP? - Symfony2: app_dev.php allow access only to IP? Symfony2-在不使用前端控件app_dev.php的情况下访问开发人员缓存 - Symfony2 - Access dev cache without using the front controlleur app_dev.php Symfony2 app.php 接收 POST 请求作为 GET app_dev.php 工作正常 - Symfony2 app.php receiving POST request as GET app_dev.php works fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM