且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-10-17 18:07:10

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

...大量文字...</目录>

确保具有:

允许覆盖所有</目录>

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>