【问题标题】:Symfony 1.4: Second app on custom domain?Symfony 1.4:自定义域上的第二个应用程序?
【发布时间】:2013-11-26 21:17:29
【问题描述】:

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

    […]

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

    在 ~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.app.example.com的配置中的AllowOverride None.htaccess没有被解释,所以改变它没有效果。
    【解决方案2】:

    我通过改变让它工作:

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

    进入:

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 2023-01-16
      相关资源
      最近更新 更多