【问题标题】:CodeIgniter and specific rewrite ruleCodeIgniter 和具体的重写规则
【发布时间】:2014-09-30 23:20:55
【问题描述】:

在我的 CodeIgniter 网站上,我想添加一个特定的重写规则,以便这个 url http://www.exemple.com/cache.manifest

会改写成

http://www.exemple.com/controller/manifest

(因为 Safari 7 似乎只接受 ApplicationCache 的 .manifest 文件)

所以我尝试将此行添加到我的 htaccess 中

RewriteRule ^cache.manifest$ controller/manifest

我在其他重写规则之前添加了它:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^cache.manifest$ controller/manifest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

但它返回 404。如果我将行更改为

RewriteRule ^cache.manifest$ test.html

它有效。所以我的规则的第一部分是正确的。

如果我尝试直接访问 www.example.com/controller/manifest,它可以正常工作,所以我的网址是正确的。

我也试过了

RewriteRule ^cache.manifest$ index.php/controller/manifest [L]

但它也不起作用......

有什么线索吗?

非常感谢

【问题讨论】:

  • 你试过了吗:RewriteRule ^cache.manifest$ /index.php/controller/manifest [L] - 你可能需要 index.php 之前的 /
  • 只是为了确定,cache.manifest 是一个文件?
  • 不,cache.manifest 不存在。但这是 RewriteRule 的重点,还是我不明白你的问题?
  • 在右侧“相关”部分中的this link 之后,我发现了在 config/routes.php 文件中指定重写的能力,并且它有效! $route["cache.manifest"] = "controller/manifest"; 没有解释为什么htaccess中的rewriterule不起作用,但对我来说已经足够了(虽然safari 7 bug仍然存在)
  • CodeIgniter 的路由模块非常有用和强大。我在下面发布了一个可能有效的 Apache 解决方案,很高兴知道所以请尝试一下。感谢您的更新。

标签: codeigniter rewrite codeigniter-2 cache-manifest application-cache


【解决方案1】:

我在本地服务器上尝试了一些测试,我认为以下方法可能有效:

RewriteRule ^cache.manifest$ /index.php/controller/manifest [R,L]

我不完全确定你是否需要前导“/”或“/index.php”,所以你 可能需要试验。

您需要[R] 标志来强制重定向。在这种情况下,您需要 Apache 在 URL 中查找字符串 cache.manifest,然后转到 CI 页面 controller/manifest.

看来您需要明确设置重定向。

请让我知道这是否有效。祝你好运!

【讨论】:

  • 其实我不能加R标签,因为我需要url保留一个.manifest后缀
  • 我明白了,这是一个棘手的问题!在这种情况下,CI 路由模块就是要走的路。
  • 无论如何,非常感谢你的帮助,马克!顺便说一句,它并没有解决我的问题,因为 Safari 错误与清单名称无关,而是与 applicationCache.abort() 函数有关……:+/
猜你喜欢
  • 1970-01-01
  • 2015-03-04
  • 2013-10-21
  • 1970-01-01
  • 2014-04-12
  • 2015-02-15
  • 2010-09-25
  • 1970-01-01
相关资源
最近更新 更多