symfony 2子域动作设置

时间:2014-10-20 11:05:08

标签: php .htaccess symfony

我有这个完整的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以链接到其正确的控制器操作?

更新

即使我GET manage.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“默认”评论说

但仍未找到解决方案

1 个答案:

答案 0 :(得分:-1)

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

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