2014-06-26 49 views
0

我是Symfony的新手,刚刚学习它。尽管Symfony的文档帮助我解决了所有问题,并回答了迄今为止所有的问题,但我无法找到有关路由问题的解决方案。Symfony忽略路由的文件名

每当我访问一个页面,我需要以指定前端控制器触发路由:

http://localhost/symfony/app_dev.php/test 

我想要做清理URL进一步被省略前端控制器是什么:

http://localhost/symfony/test 

这可能是一个简单的事情,但我一直没能找到它描述了我该怎么办呢(如果它是在所有可能的)一个SO问题或文档页面。我曾尝试将前端控制器重命名为index.php,但不幸的是它也无法正常工作。

+0

您是否尝试过从网址中移除app_dev.php?如果你已经启用了mod_rewrite并且你的.htaccess没有被改变,那么它应该可以直接使用。欲了解更多信息,请参阅http://symfony.com/doc/current/quick_tour/the_big_picture.html#what-is-an-environment – qooplmao

回答

1

如果你的httpd.conf说允许压倒一切的

NameVirtualHost *:80 
<VirtualHost *:80> 
    ServerName foo.localhost.com 
    DocumentRoot "/Projects/YourProject/web" 
    <Directory "/Projects/YourProject/web"> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Allow from All 
    </Directory> 
</VirtualHost> 

您可以使用此Web/.htacces

# Use the front controller as index file. It serves as a fallback solution when 
# every other rewrite/redirect fails (e.g. in an aliased environment without 
# mod_rewrite). Additionally, this reduces the matching process for the 
# start page (path "/") because otherwise Apache will apply the rewriting rules 
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). 
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] ##### this is the part that you  should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially 
    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 
    RewriteRule .? %{ENV:BASE}/app_dev.php [L]  ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     # When mod_rewrite is not available, we instruct a temporary redirect of 
     # the startpage to the front controller explicitly so that the website 
     # and the generated links can still be used. 
     RedirectMatch 302 ^/$ /app_dev.php/ 
     # RedirectTemp cannot be used instead 
    </IfModule> 
</IfModule> 

一定ifmodule启用; link

所以在您的督促环境你app.php

取代app_dev.php您可能还需要为每个环境不同的参数,最好要做到这一点是把它变成的.gitignore 创造两个文件:

parameters.prod.yml 
parameters.dev.yml 

,并根据阶段创建parameters.yml文件在同一目录就像一个符号链接:

ln -s parameters.dev.yml parameters.yml