Symfony2 - 如何从我的网址中删除“web/app_dev.php/"? [英] Symfony2 - How can I remove 'web/app_dev.php/' from my url?

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

问题描述

当我希望我的 symfony 网站上线时,如何从我的网址中删除web/app_dev.php/"?

How can I remove 'web/app_dev.php/' from my url when I want my symfony website to go live?

这是开发过程中的默认网址,

This is the default url during development,

http://{localhost}/my-symfony-2/web/app_dev.php/hello/World

所以当我上线时,我希望能够使用这个 URL 访问我的 symfony 网站,

So when I go live, I would like to be able to use this url to access my symfony website,

http://my-symfony-2.com/hello/World

有什么想法吗?

推荐答案

要隐藏 app.php,您需要:

  1. 至少可以访问您网站的 Web 根目录.通常在您的虚拟主机空间的控制面板上,您可以找到可以从中上传文件的文件(或者,如果您拥有访问凭据,则可以安装和使用免费的 FTP 客户端,例如 Filezilla).
  2. 检查您是否在 Apache 中安装并启用了 mod_rewrite 模块,查看apache2handler"下的 phpinfo() --->Loaded Modules"目录(您应该可以直接通过控制面板进行).
  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).
  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).

在这些检查之后,您必须:

After these checks you have to:

注意:Symfony2 已经带有一个存储在默认 Web 目录中的 .htaccess 文件,但如果你不知道你在做什么,最好替换指令IfModule mod_rewrite.c"中的容器,如下所示.

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.

  1. 使用原生 Symfony2 .htaccess 或创建一个带有 .htaccess 扩展名的新文件,并在这些指令中复制/粘贴以隐藏 app.php 在生产中(不在本地主机上):

  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):

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

要应用您需要重新启动 Apache 的修改(这通常也是在您的网络空间的控制面板上进行的).

To apply the modifications you need to restart Apache (also this is usually did on the control panel of your web space).

谷歌一下,你可以找到大量的例子和教程,但要开始学习,看看这个简单的.htaccess 指南,包含许多有用的信息和示例官方URL 重写指南 (Apache2.4).如果您遇到一些问题,请更新您的帖子,添加所有相关信息,否则您可以在此处提出另一个问题.

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). If you encounter some problem update your post adding all related infos otherwise you can make another question here on SO.

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

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