Symfony 1.4:自定义域上的第二个应用程序?

时间:2013-11-26 21:17:30

标签: mod-rewrite routing symfony1 apache2 symfony-1.4

PHP启动脚本:

  • 主要应用:

    ~ec2-user/project/web/index.php
    
  • 辅助应用:

    ~ec2-user/project/web/api1.php
    

Apache配置:

  • 摘录自/etc/httpd/conf/httpd.conf

    <VirtualHost *:80>
        ServerName example.com
    
        DocumentRoot /home/ec2-user/project/web
        DirectoryIndex index.html index.php
        <Directory /home/ec2-user/project/web>
            AllowOverride All
            Allow from All
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName 1.api.example.com # 1: version number
    
        DocumentRoot /home/ec2-user/project/web
        <Directory /home/ec2-user/project/web>
            AllowOverride None
        </Directory>
    
        RewriteEngine On
        RewriteRule ^(.*)$ /api1_dev.php [QSA,L]
    </VirtualHost>
    
  • ~ec2-user/project/web/.htaccess(仅适用于主应用):

    Options +FollowSymLinks +ExecCGI
    
    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      # uncomment the following line, if you are having trouble
      # getting no_script_name to work
      #RewriteBase /
    
      # we skip all files with .something
      #RewriteCond %{REQUEST_URI} \..+$
      #RewriteCond %{REQUEST_URI} !\.html$
      #RewriteRule .* - [L]
    
      # we check if the .html version is here (caching)
      RewriteRule ^$ index.html [QSA]
      RewriteRule ^([^.]+)$ $1.html [QSA]
      RewriteCond %{REQUEST_FILENAME} !-f
    
      # no, so we redirect to our front web controller
      RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    

按预期加载什么:

  • http://example.com:主页

  • http://example.com/api1.php/foo/bar:一些JSON数据

什么不加载:

  • http://1.app.example.com/foo/bar

      

    404 |找不到| sfError404Exception

         

    解析URL“/”(/)。

    后清空模块和/或操作      

    [...]

我缺少什么?

2 个答案:

答案 0 :(得分:0)

在~ec2-user / project / web / .htaccess,

取消注释RewriteBase /,它变为:

Options +FollowSymLinks +ExecCGI

RewriteEngine On

# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /

# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]

# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]

答案 1 :(得分:0)

我通过改变来实现它:

RewriteRule ^(.*)$ /api1_dev.php [QSA,L]

成:

RewriteRule ^(.*)$ /api1_dev.php/$1 [QSA,L]

有道理。我只想知道为什么.htaccess example.com$1 没有必要:

RewriteRule ^(.*)$ index.php [QSA,L]