Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用 [英] Codeigniter URL rewriting .htaccess is not working on CentOS

查看:38
本文介绍了Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

例如更改 URL 来自

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

http://myhost/controller/function`

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

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^(.*)$ 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 中,您应该看到如下内容:

<目录/var/www/html">...大量文字...</目录>

确保具有:

<目录/var/www/html">允许覆盖所有</目录>

I've created a .htaccess file in my document root at /var/www/html/ to rewrite URL of Codeigniter to remove "index.php" from URL of all pages.

e.g. Change URL from

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

to

http://myhost/controller/function`

Here is the code of my `/var/www/html/.htaccess

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

I've got many suggestions from googling to enable mod-rewrite module, but I can see in my httpd.conf its already enabled.

LoadModule rewrite_module modules/mod_rewrite.so

This is perfectly working on my local system running on Debian 7 (Apache/2.4.4).

Any help would be appreciated. :)

解决方案

You need to also specify the locations that can use it. For example, in /etc/httpd/conf/httpd.conf you should see something like:

<Directory "/var/www/html">

      ...lots of text...

</Directory>

Make sure is has:

<Directory "/var/www/html">

    AllowOverride All

</Directory>

这篇关于Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆