【问题标题】:.htaccess RewriteBase not working.htaccess RewriteBase 不工作
【发布时间】:2015-11-16 04:23:29
【问题描述】:

我正在使用 .htaccess 删除我的 CodeIgniter 项目的 index.php。我让它在 localhost 中正常工作,但在我的托管中失败了。我的主机向我展示的结构是这样的:

/
-- domains
---- mydomain.com
------ public_html
-------- .htaccess
-------- (the rest of my CI site)

在 localhost 我的 .htaccess 是这样的:

RewriteEngine on
RewriteBase /myCIfolder/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我尝试过的:

RewriteBase /
RewriteBase /domains/
RewriteBase /domains/mydomain.com/
RewriteBase /domains/mydomain.com/public_html/
RewriteBase /mydomain.com/
RewriteBase /mydomain.com/public_html/
RewriteBase /public_html/

但我无法让它工作。我已经问过我的主机提供商,他们说 MOD_REWRITE 已经启用。

高度赞赏任何想法。


编辑 1

我的索引页面(mydomain.con -- 主控制器,索引函数)正在正确加载,但任何其他控制器都失败了。

RewriteBase /

它显示了错误:

没有指定输入文件。

任何其他 RewriteBase 显示:

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。

请联系服务器管理员 webmaster@mydomain.com 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。

服务器错误日志中可能会提供有关此错误的更多信息。

此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。

mydomain.com 端口 80 上的 Apache/2 服务器

【问题讨论】:

  • “不起作用”到底是什么意思?您是否收到任何可以发布的错误消息(或者 apache 会产生什么)?如果 public_html 是您的文档根目录并且文件 index.php 在此目录中找到,则它应该与 RewriteBase / 一起使用,因为这是在根目录的 url 和 RewriteRule 的结果之间输入的内容。 %{REQUEST_FILENAME ... 告诉规则只处理任何不是文件或目录的东西,这应该没问题,因为你想将任何请求传递给你的前端控制器 index.php,对吗?
  • 是的。我已经更新了我的问题。 RewriteBase / 显示“未指定输入文件”。只发消息。感谢您为我澄清这一点。

标签: apache .htaccess codeigniter


【解决方案1】:

感谢@Fuzzzzel 的评论,我已经解决了这个问题,它把我带到了this

所以我将 .htaccess 更改为

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)

RewriteRule ^(.*)$ index.php?/$1 [L]

它终于奏效了。谢谢! :)

【讨论】:

  • 好的,那么您在调用您的网站时没有指定文件,而只是输入了域名本身。这没有找到索引文件(通常具有扩展名 .htm 或 .html),因此您必须通过 DirectoryIndex 指定它。很高兴你明白了。
猜你喜欢
  • 2010-10-16
  • 2012-02-10
  • 2013-05-17
  • 2013-08-27
  • 2020-06-21
  • 1970-01-01
  • 1970-01-01
  • 2016-12-31
  • 2012-03-14
相关资源
最近更新 更多