Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Symfony:htaccess隐藏app.php或app_dev.php_.htaccess_Symfony - Fatal编程技术网

.htaccess Symfony:htaccess隐藏app.php或app_dev.php

.htaccess Symfony:htaccess隐藏app.php或app_dev.php,.htaccess,symfony,.htaccess,Symfony,我知道这个问题已经被问过很多次了,但是一些奇怪的事情正在发生在我身上。Apache DocumentRoot指向symfony/web/,这是web/dir中的my.htaccess: DirectoryIndex app_dev.php #DirectoryIndex app.php <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} ^$ Rewrit

我知道这个问题已经被问过很多次了,但是一些奇怪的事情正在发生在我身上。Apache DocumentRoot指向symfony/web/,这是web/dir中的my.htaccess:

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>
DirectoryIndex应用程序\u dev.php
#DirectoryIndex app.php
重新启动发动机
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^app\.php(/(.*)|$)%{CONTEXT_PREFIX}/$2[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则^(.*)$app_dev.php[QSA,L]
#重写规则^(.*)$app.php[QSA,L]
RewriteCond%{REQUEST_URI}:$1^(/.+)(.+):\2$
重写规则^(.*)-[E=基:%1]
重写规则.?%{ENV:BASE}app.php[L]
重定向匹配302^/$/app.php/
好的,事情是
www.example.com/route1/
正在工作,而
www.example.com/route2/
正在抛出一个错误:

哎呀!发生了一个错误 服务器返回“404未找到”。 有东西坏了。请通过[电子邮件]向我们发送电子邮件,并告知发生此错误时您正在执行的操作。我们会尽快修好的。不便之处,敬请原谅

www.example.com/app_dev.php/route2/
工作正常(同样
www.example.com/app_dev.php/route1/

帮忙

更新。prod中的缓存清除抛出此错误(我以前从未尝试过,我正在开发):

[原则\Common\Proxy\Exception\UnexpectedValueException] 类“MyProject\PanelBundle\Entity\User”中方法“addRole”中参数“userRoles”的类型提示无效

[反射异常] 类Maycol\BlogBundle\Entity\Role不存在


此错误与Apache/htaccess无关。这个404错误页面是symfony本身的默认页面

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.
没有路由匹配/路由2。按如下方式检查您的路由:

php app/console router:debug 
要更快地检查,请使用grep或findstr(Windows)

还请检查您的路由是否不仅在dev环境中配置(即仅在routing_dev.yml中配置)

请用…清除您的产品缓存

php app/console cache:clear --env=prod
。。。如果访问404页面时出现未捕获的异常,请检查日志文件。例如,您可以使用此命令查看生产日志文件中的实时更改

tail -f app/logs/prod.log

此错误与Apache/htaccess无关。这个404错误页面是symfony本身的默认页面

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.
没有路由匹配/路由2。按如下方式检查您的路由:

php app/console router:debug 
要更快地检查,请使用grep或findstr(Windows)

还请检查您的路由是否不仅在dev环境中配置(即仅在routing_dev.yml中配置)

请用…清除您的产品缓存

php app/console cache:clear --env=prod
。。。如果访问404页面时出现未捕获的异常,请检查日志文件。例如,您可以使用此命令查看生产日志文件中的实时更改

tail -f app/logs/prod.log

这是为我工作的.htaccess:

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>
DirectoryIndex app.php
#DirectoryIndex应用程序_dev.php
重新启动发动机
#重定向到不带前端控制器的URI以防止重复内容
#(带或不带“/app.php”)。仅在初始路径上执行此重定向
#由Apache重写,而不是在后续周期中重写。否则我们会被解雇
#无休止的重定向循环(请求->重写到前端控制器->
#重定向->请求->…)。
#所以,如果你得到一个“太多重定向”错误或你总是得到重定向
#因为您的Apache没有公开重定向的状态
#环境变量,您有两种选择:
#-通过注释以下两行或两行禁用此功能
#-使用Apache>=2.3.9,用结束标志替换所有L标志,并删除
#第二步(最佳解决方案)
RewriteCond%{ENV:REDIRECT_STATUS}^$
#重写规则^app_dev\.php(/(.*)|$)%{CONTEXT_PREFIX}/$2[R=301,L]
重写规则^app\.php(/(.*)|$)%{CONTEXT_PREFIX}/$2[R=301,L]
#如果请求的文件名存在,只需提供它即可。
#我们只想让Apache服务于文件,而不是目录。
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
RewriteCond%{REQUEST_FILENAME}-f
#重写规则^(.*)$app_dev.php[QSA,L]
重写规则^(.*)$app.php[QSA,L]
#下面将所有其他查询重写到前端控制器。这个
#条件确保,如果您使用Apache别名进行大规模虚拟
#宿主时,将预先设置基本路径,以允许正确解析
#php文件;它也可以在无别名的环境中工作,提供
#一个安全、一刀切的解决方案。
RewriteCond%{REQUEST_URI}:$1^(/.+)(.+):\2$
重写规则^(.*)-[E=基:%1]
#重写规则.?%{ENV:BASE}app_dev.php[L]
重写规则.?%{ENV:BASE}app.php[L]
#当mod_rewrite不可用时,我们指示临时重定向
#将起始页显式地发送到前端控制器,以便网站
#生成的链接仍然可以使用。
#重定向匹配302^/$/app_dev.php/
重定向匹配302^/$/app.php/
#不能改为使用RedirectTemp

这是为我工作的.htaccess:

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>
DirectoryIndex app.php
#DirectoryIndex应用程序_dev.php
重新启动发动机
#重定向到不带前端控制器的URI以防止重复内容
#(带或不带“/app.php”)。仅在初始路径上执行此重定向
#由Apache重写,而不是在后续周期中重写。否则我们会被解雇
#无休止的重定向循环(请求->重写到前端控制器->
#重定向->请求->…)。
#所以,如果你得到一个“太多重定向”错误或你总是得到重定向
#因为您的Apache没有公开重定向的状态
#环境变量,您有两种选择:
#-通过注释以下两行或两行禁用此功能
#-使用Apache>=2.3.9并替换所有L