PHP / Symfony2中从URL隐藏app.php [英] php/symfony2 hiding app.php from the URL
问题描述
考虑以下网址: http://www.myurl.fr/accueil
这是行不通的。然而 http://www.myrurl.fr/app.php/accueil 确实工作。
It won't work. However http://www.myrurl.fr/app.php/accueil does work.
我摆脱了.htaccess文件,因为我想用虚拟主机文件,并依赖于Apache的路由。我的虚拟主机文件如下:
I got rid of the .htaccess file because I want to use the vhost file and rely on Apache routing. My vhost file is as follow:
<VirtualHost my.ip.address>
ServerName myurl.fr
ServerAlias www.myurl.fr
DocumentRoot /var/www/mysite/web
DirectoryIndex app.php
<Directory "/var/www/mysite/web">
AllowOverride All
Allow from All
</Directory>
<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>
</VirtualHost>
我已经清空缓存的Apache并重新启动了很多次。该urlrewritemod已启用。我只是不知道要检查什么。任何想法,我缺少的是什么?
I've cleared Apache cache and restarted it many times. The urlrewrite mod is enabled. I just don't know what else to check. Any idea what I'm missing ?
修改
这可能是因为我的工作就可以了两个URL不会在特定的时间工作。我的问题仍然有效。
EDIT It could be that both URL won't work at a given time since I'm working on it. My issue is still valid.
推荐答案
在symfony标准的的.htaccess ,我看到你错过了文件前检查通过一切规则。尝试
Compared your rules with symfony-standard .htaccess, I saw that you missed file checking before 'pass everything rule'. Try to
<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]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
这篇关于PHP / Symfony2中从URL隐藏app.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!