2018-09-03 11:30 阅读 29

Symfony .htaccess - 500个三级域名

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 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 !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/

and this is my app.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 = 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 = Request::createFromGlobals();
$response = $kernel->handle($request);
$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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    drf16571 drf16571 2018-09-22 09:19

    I resolve this adding again the redirect to third domain level, like this:

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

    I didnt think that I must the redirect all the request under my project, not only the root.

    点赞 评论 复制链接分享