linux - Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用

标签 linux apache .htaccess codeigniter mod-rewrite

我在位于 /var/www/html/ 的文档根目录中创建了一个 .htaccess 文件,以重写 Codeigniter 的 URL,从所有页面的 URL 中删除“index.php”。

例如更改 URL 来自

http://myhost/index.php/controller/function

http://myhost/controller/function`

这是我的`/var/www/html/.htaccess 的代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

我从谷歌搜索中得到了很多启用 mod-rewrite 模块的建议,但我可以在我的 httpd.conf 中看到它已经启用。

LoadModule rewrite_module modules/mod_rewrite.so

这在运行 Debian 7 (Apache/2.4.4) 的本地系统上运行完美。

如有任何帮助,我们将不胜感激。 :)

最佳答案

您还需要指定可以使用它的位置。例如,在/etc/httpd/conf/httpd.conf 中,您应该看到如下内容:

<Directory "/var/www/html">

      ...lots of text...

</Directory>

确保有:

<Directory "/var/www/html">

    AllowOverride All

</Directory>

关于linux - Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20710569/

相关文章:

c - 访问 GPIO AM335x 板作为 RESET 和最小 CPU 使用率

c - 如何从linux库传递c中的参数

linux - 测试命令和重定向 bash

php - .htaccess 未运行 mod-rewrite 或未执行

php - 在 .htaccess 文件中设置 open_basedir 会完全限制 PHP 脚本目录访问吗?

apache - 当 Apache .htaccess 上的 HTTP 方法是 OPTIONS 时,如何避免请求基本身份验证?

python - 从 Python 更新 proc 条目的推荐方法是什么

java - tomcat中奇怪的IP地址

javascript - 单击一个按钮以在 PHP 中运行 casperJS 并在带有按钮的同一 PHP 页面中回显结果

php - 使用 mod_rewrite 将文件夹转换为查询字符串