【问题标题】:Symfony 1.4 routing issues only when using index.php and mod_rewriteSymfony 1.4 路由问题仅在使用 index.php 和 mod_rewrite 时出现
【发布时间】:2011-05-25 14:10:58
【问题描述】:

总结手头问题的最简洁方式:

  • 开发已经结束,在开发和测试过程中一切都在frontend_dev.php上运行

    这意味着所有网址都是:server.com/frontend_dev.php/module/action/parm

  • 迁移到生产意味着切换环境,因此改用 index.php
    server.com/index.php/module/action/parm

  • 转向生产的一部分是在 Apache2 下使用 mod_rewrite 使 URL 的“index.php”部分消失,但仍然可以正常工作
    server.com/module/action/parm 仍然针对 index.php 进行路由

  • 确实出现了没有 index.php 部分的 URL,但是 symfony 路由现在抱怨:
    即,server.com/goals 路由到目标/索引
    -- 使用 frontend_dev.php 或 index.php 作为显式控制器非常好
    server.com/index.php/goals
    -- 不使用显式控制器(通过重写):
    [Tue Dec 14 12:59:51 2010] [error] [client 75.16.181.113] Empty module and/or action after parsing URL "/goals /" (/)

我已通过将重写更改为不存在的内容来验证重写确实路由到 index.php:
[Tue Dec 14 13:05:43 2010] [error] [client 75.16 .181.113] 脚本 '/opt/www/projects/adam/web/index2.php' 未找到或无法统计

我已经尝试重新路由到 frontend_dev.php,但只提供了来自 symfony 的更多调试信息,这些都没有帮助:

404 |未找到 | sfError404Exception 解析 URL “/goals/” (/) 后的空模块和/或操作。
堆栈跟踪
1. SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php 第 44 行中的 at () ...
2. 在 SF_SYMFONY_LIB_DIR/util/sfContext.class.php 第 170 行中的 sfFrontWebController->dispatch() ...
3. 在 SF_ROOT_DIR/web/frontend_dev.php 第 13 行中的 sfContext->dispatch() ...

我已经尝试在 .htaccess 中使用 RewriteBase 选项,但这没有任何帮助,也没有更改控制器配置行中的真/假

我希望这足以让我们理解为什么我们会感到困惑,并能够指导我们解决问题。

以下是当前的 .htaccess 和 index/frontend 配置行

索引.php:

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);

前端开发.php:

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);

.htaccess:

重写引擎开启

# 如果遇到问题,请取消注释以下行 # 让 no_script_name 工作 #RewriteBase /

# 我们跳过所有带有 .something 的文件 #RewriteCond %{REQUEST_URI} ..+$ #RewriteCond %{REQUEST_URI} !.html$ #RewriteRule .* - [L]

# 我们检查 .html 版本是否在这里(缓存) 重写规则 ^$ index.html [QSA] 重写规则 ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f

# 不,所以我们重定向到我们的前端 Web 控制器 RewriteRule ^(.*)$ index.php [QSA,L]

【问题讨论】:

  • 当请求被正确重写时,symfony 抱怨找不到路由,这似乎很奇怪 - 您是否尝试过通过 index.php 将路由配置直接转储到浏览器?并手动清除缓存,也许?另外,尝试重写你的 index2.php 并让它打印查询。
  • 你能发布你的 routing.yml 吗?

标签: mod-rewrite symfony1 routing routes


【解决方案1】:

欢迎来到 Stack Overflow。

也许您将“index”路由与“index.php”混淆了?

理论上,这些 URL 应该都可以工作。

server.com/frontend_dev.php/goals/index  
server.com/index.php/goals/index  
server.com/goals/index  
server.com/goals

我不记得尾部的斜杠(如server.com/goals/)是否有效。有一个问题。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,在 Virtual Host 的配置中将 Symfony 的 WEB 文件夹的“AllowOverride”设置为 ALL 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多