Symfony的:htaccess的隐藏app.php或app_dev.php [英] Symfony: htaccess to hide app.php or app_dev.php
问题描述
我知道这已经被问了很多次,但一些奇怪的事情发生在我身上。阿帕奇的DocumentRoot指向的的symfony /网络/ 的,这是我的.htaccess网/目录里:
的DirectoryIndex app_dev.php
#DirectoryIndex app.php
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteCond%{ENV:REDIRECT_STATUS} ^ $
重写规则^程序\的.php(/(.*)| $)%{CONTEXT_ preFIX} / $ 2 [R = 301,L]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则? - [L]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则^(。*)$ app_dev.php [QSA,L]
#RewriteRule ^(。*)$ app.php [QSA,L]
的RewriteCond%{REQUEST_URI} :: $ l ^(/.+)(+):: \ 2 $
重写规则^(。*) - [E = BASE:%1]
重写规则? %{ENV:BASE} app.php [L]
< / IfModule>
<!IfModule mod_rewrite.c>
< IfModule mod_alias.c>
RedirectMatch 302 ^ / $ /app.php/
< / IfModule>
< / IfModule>
好了,事情是 www.example.com/route1 /
是工作和 www.example.com/route2 /
抛出一个错误:
哎呀!发生错误 服务器返回一个404未找到。 东西坏了。请发邮件给我们:[邮件],并让我们知道你在做什么时,出现此错误。我们将尽快修复它。给您造成的任何不便,请原谅。
在 www.example.com/app_dev.php/route2 /
正在确定(也 www.example.com/app_dev.php/ ROUTE1 /
)
帮助?
更新。缓存清理在督促引发此错误(我从来没有尝试过,我正在开发):
[主义\公用\代理\异常\ UnexpectedValueException] 参数userRoles的方法类型提示addRole类MyProject的\ PanelBundle \实体\用户是无效的。
[ReflectionException] 类Maycol \ BlogBundle \实体\角色不存在
这是为我工作的.htaccess:
的DirectoryIndex app.php
#DirectoryIndex app_dev.php
< IfModule mod_rewrite.c>
RewriteEngine叙述上
#重定向到URI不前端控制器prevent重复的内容
#(带或不带`/ app.php`)。只有做到这一点重定向初始
#重写阿帕奇,而不是在随后的周期。否则,我们将得到一个
#无尽的重定向循环(要求 - >重写前端控制器 - >
#重定向 - >要求 - > ...)。
#所以,如果你得到一个过多的重定向错误,或者你总是重定向
#到起始页,因为你的Apache不公开REDIRECT_STATUS
#环境变量,你有两个选择:
# - 通过注释下面的两行禁用此功能,或
# - 使用Apache> = 2.3.9和结束标志全部更换l标志和删除
#以下的RewriteCond(最佳解决方案)
的RewriteCond%{ENV:REDIRECT_STATUS} ^ $
#RewriteRule ^ app_dev \的.php(/(.*)| $)%{CONTEXT_ preFIX} / $ 2 [R = 301,L]
重写规则^程序\的.php(/(.*)| $)%{CONTEXT_ preFIX} / $ 2 [R = 301,L]
#如果请求的文件存在,只是为它服务。
#我们只希望让Apache处理文件,而不是目录。
的RewriteCond%{} REQUEST_FILENAME -f
重写规则? - [L]
的RewriteCond%{} REQUEST_FILENAME -f
#RewriteRule ^(。*)$ app_dev.php [QSA,L]
重写规则^(。*)$ app.php [QSA,L]
#下面重写所有其他查询到前端控制器。该
#条件保证,如果你使用的是Apache的别名做好群众虚拟
#托管,基本路径将是prepended允许的妥善解决
#app.php文件;它会在不走样的环境中工作,以及提供
#一个安全,一个放之四海而皆准的解决方案。
的RewriteCond%{REQUEST_URI} :: $ l ^(/.+)(+):: \ 2 $
重写规则^(。*) - [E = BASE:%1]
#RewriteRule? %{ENV:BASE} app_dev.php [L]
重写规则? %{ENV:BASE} app.php [L]
< / IfModule>
<!IfModule mod_rewrite.c>
< IfModule mod_alias.c>
#当mod_rewrite的不可用,我们指示的临时重定向
#在起始页的前端控制器明确,使网站
#和所生成的链路仍然可以使用。
#RedirectMatch 302 ^ / $ /app_dev.php/
RedirectMatch 302 ^ / $ /app.php/
#RedirectTemp不能用来代替
< / IfModule>
< / IfModule>
I know this has been asked many times, but something strange is happening to me. Apache DocumentRoot is pointing to symfony/web/ and this is my .htaccess inside web/ dir:
DirectoryIndex app_dev.php
#DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
#RewriteRule ^(.*)$ app.php [QSA,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Well, the thing is www.example.com/route1/
is working and www.example.com/route2/
is throwing an error:
Oops! An Error Occurred The server returned a "404 Not Found". Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
While www.example.com/app_dev.php/route2/
is working ok (also www.example.com/app_dev.php/route1/
)
Help?
Update. Cache clear in prod throws this error (I never tried before, I'm working on dev):
[Doctrine\Common\Proxy\Exception\UnexpectedValueException] The type hint of parameter "userRoles" in method "addRole" in class "MyProject\PanelBundle\Entity\User" is invalid.
[ReflectionException] Class Maycol\BlogBundle\Entity\Role does not exist
This is the .htaccess that worked for me:
DirectoryIndex app.php
#DirectoryIndex app_dev.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteRule ^app_dev\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$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]
RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule ^(.*)$ app_dev.php [QSA,L]
RewriteRule ^(.*)$ app.php [QSA,L]
# The following rewrites all other queries to the front controller. The
# condition ensures that if you are using Apache aliases to do mass virtual
# hosting, the base path will be prepended to allow proper resolution of the
# app.php file; it will work in non-aliased environments as well, providing
# a safe, one-size fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
#RewriteRule .? %{ENV:BASE}app_dev.php [L]
RewriteRule .? %{ENV:BASE}app.php [L]
</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/
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
这篇关于Symfony的:htaccess的隐藏app.php或app_dev.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!