2013-11-26 41 views
0

PHP启动脚本:Symfony 1.4:自定义域上的第二个应用程序?

  • 主要应用:

    ~ec2-user/project/web/index.php 
    
  • 次要应用程式:

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

Apache配置:

    0从
  • 摘录:

    <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“/”(/)后为空模块和/或动作。

    [...]

我缺少什么?

回答

0

我把它通过改变工作:

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

纳入:

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

有道理。我只是想知道为什么在.htaccessexample.com,该$1 是没有必要的:

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

在EC2〜用户/项目/网络/的.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] 
+0

请注意,'的AllowOverride None'在'1.app.example.com'配置:'.htaccess'不解释,所以改变它没有效果。 – feklee

相关问题