php / symfony2从URL隐藏app.php

前端之家收集整理的这篇文章主要介绍了php / symfony2从URL隐藏app.php前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请考虑以下URL: http://www.myurl.fr/accueil.

它不会起作用.但是http://www.myrurl.fr/app.php/accueil确实有效.

我摆脱了.htaccess文件,因为我想使用vhost文件并依赖Apache路由.我的vhost文件如下:

<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缓存并重启了很多次. urlrewrite mod已启用.我只是不知道还有什么要检查.知道我错过了什么吗?

编辑
可能是因为我正在处理它,两个URL都不会在给定时间工作.我的问题仍然有效.

将您的规则与symfony-standard .htaccess进行比较,我发现您在“传递所有规则”之前错过了文件检查.尝试
<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>
原文链接:https://www.f2er.com/php/132604.html

猜你在找的PHP相关文章