首页 > 解决方案 > Symfony .htaccess - 500 third level domain

问题描述

I'm my application on subdirectory in www.example.com/aplication/v1 and I have a third level domain to this in v1.example.com. I'm using symfony2 and in my .htacess I have this:

DirectoryIndex app.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization

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

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

and this is my app.php

 <?php

use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/bootstrap.php.cache';

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

All works well in www.example.com/aplication/v1, but 500 if I try v1.example.com. I ask to support of my hosting and They say the problem is in my .htacess. How fix it?

update: Maybe I must update my rewrite condition in .htaccess?

标签: php.htaccesssymfony

解决方案


我解决了这个问题,再次将重定向添加到第三个域级别,如下所示:

 #redirect for service
    RewriteCond %{HTTPS_HOST} ^v1\.example\.com
    RewriteRule ^(.*)$ /application/v1/$1 [L]

我不认为我必须重定向我项目下的所有请求,而不仅仅是根。


推荐阅读