【问题标题】:symfony 2 subdomains action setupsymfony 2 子域操作设置
【发布时间】:2014-10-20 11:05:07
【问题描述】:

我有完整的routing 配置文件

#routing.yml
admin_hello:
    resource: "@WebsiteOnePageBundle/Resources/config/routing_admin.yml"
    host:     "manage.website.com"

website_one_page:
    resource: "@WebsiteOnePageBundle/Resources/config/routing.yml"

我的问题是,如果我 GETPOST manage.website.com/ 触发登录操作。如果我 GET 或 POST manage.website.com/users 我的 usersAction 没有被触发,我得到 500 内部服务器错误。

官方docs 对此只字未提。

apache 日志说

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://manage.website.com/

如何避免这种内部重定向?或更好... 我如何设置子域 URI 以链接到其正确的控制器操作?

更新

即使我GETmanage.website.com/whatever出现同样的错误...

其他有用的配置信息:

provider => godaddy

子域的重定向文件夹(我为两个子域使用了相同的文件夹)

manage.website.com => /web
www.website.com => /web

在谷歌上搜索这个错误,我发现这是一个与.htaccess 相关的问题。这是我的 (/web/.htaccess)

# 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

    # Determine the RewriteBase automatically and set it as environment variable.
    # If you are using Apache aliases to do mass virtual hosting or installed the
    # project in a subdirectory, the base path will be prepended to allow proper
    # resolution of the app.php file and to redirect to the correct URI. It will
    # work in environments without path prefix as well, providing a safe, one-size
    # fits all solution. But as you do not need it in this case, you can comment
    # the following 2 lines to eliminate the overhead.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # 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 start page 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\.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>

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

尝试评论和取消评论

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

symfony “默认” cmets 所说的行

但还没有找到解决办法

【问题讨论】:

  • 某些东西正在覆盖您的路由,可能是之前的路由,也可能是您 security.yml 中的防火墙设置。您可以发布完整的routing.ymlsecurity.yml 吗?请记住,Symfony 解析到它找到的第一条路由,因此在您的带有host 参数的路由之前找到的任何路由都将首先使用。这包括不使用host 参数的路由,因为它们适用于任何主机。在这种情况下,Symfony 分析器也会有所帮助(使用“查看最近 10 次”搜索)
  • 即使我 GET manage.website.com/asd 也会出现同样的错误...
  • GoDaddy 很可能是您的问题...它是“子域重定向”还是子域别名?如果你在本地环境中测试它,你能复制这个问题吗?在您的计算机上运行 LAMP、WAMP 或 MAMP 堆栈,复制您的数据库,将其指向您的 Symfony /web 文件夹,然后修改您的主机文件以将 manage.website.comseller.website.comwww.website.com 指向 127.0.0.1
  • 不是别名或重定向。卖家和管理是我的 DNS 区域(主机)中的 A 记录。
  • 嗯...有点可疑,我认为您的 Symfony 配置不会导致这个问题...

标签: php .htaccess symfony


【解决方案1】:

将这些行添加到我的.htaccess 可以解决问题

RewriteBase /
RewriteRule ^(.*)$ app.php?/$1 [NC,L,QSA]

【讨论】:

  • 你至少应该告诉我们你在哪里添加了这些行。这在 htaccess 文件中非常重要。
猜你喜欢
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 2013-02-19
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多