【问题标题】:.htaccess not working on codeigniter subdomain & directory install.htaccess 不适用于 codeigniter 子域和目录安装
【发布时间】:2012-07-09 00:14:55
【问题描述】:

我正在尝试将 CI 安装在一个目录下,该目录也在子域上。所以我的基本网址看起来像http://subdomain.domain.com/ci/

以下 htaccess 在域的根目录上运行良好,但在目录上运行良好,浏览器说存在重定向循环错误。

这是我的代码:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^sub\.domain\.com/ci/$
RewriteRule ^(.*)$ http://sub.domain.com/ci/$1 [L,R=301]

RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php?/$1 [L]

我对mod重写不是很熟练,任何帮助将不胜感激!谢谢!

【问题讨论】:

  • 您需要更明确地说明您希望 url 结构看起来如何的结果。您对 %{HTTP_HOST} 的使用将是最初的问题,因为这将忽略尾随 /ci 这可能是您获得重定向循环的原因
  • 我希望我的 CodeIgniter 基本安装位于:subdomain.domain.com/ci/index.php 所以我的正常控制器方法看起来像:subdomain.domain.com/ci/method 你提到了 %{HTTP_HOST},我应该完全删除它吗?或使用其他东西?这个 htaccess 代码不是我的代码,我在一年前或更长时间之前找到了它。谢谢
  • 但是您还希望对subdomain.domain.com 的任何请求转发到subdomain.domain.com/ci
  • 不,subdomain.domain.com 根本不会被使用,我正在为客户编写一个小应用程序,这就是他想要安装的位置,在这个目录下。 .htaccess 文件将放置在目录中,而不是域的根目录中。 sub.domain.com/ci/.htaccess

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

在您的 /ci 目录中,您的 htaccess 应该如下所示

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f # this means if the requested file name doesnt exist 
RewriteCond %{REQUEST_FILENAME} !-d # this means if the requested directory doesnt exist 
RewriteRule ^(.*)$ index.php [L]

根据你上面的 cmets 应该足够了

【讨论】:

  • 非常感谢,乍一看似乎可以正常工作。我将测试一些东西,如果一切顺利,我会很快将其标记为答案。欣赏!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-11
相关资源
最近更新 更多