CodeIgniter URL路由不起作用

时间:2013-04-14 15:59:35

标签: php .htaccess codeigniter url-rewriting routing

我正在使用Ubuntu 12.10。我无法从我的codeigniter网站网址中删除“index.php”。

我的.htaccess文件看起来像这样,我的代码在hmvcExample文件夹中。

*

RewriteEngine On
RewriteBase /hmvcExample/

### Canonicalize codeigniter URLs

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]

###

# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]   

# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php   

*

我已经从config.php中删除了“index.php”。但是当我尝试加载没有“index.php”

的网站时,我仍然会收到以下错误

未找到 在此服务器上找不到请求的URL / hmvcExample / signup。 位于localhost端口80的Apache / 2.2.22(Ubuntu)服务器

请帮助。感谢。

2 个答案:

答案 0 :(得分:2)

这似乎应该是一直在寻找的问题之一 - How to remove "index.php" in codeigniter's path

还需要编辑另一个config

$config['uri_protocol'] = 'AUTO';

将上面写的行更改为以下内容:

$config['uri_protocol'] = 'REQUEST_URI';

如果您已完成所有这些操作,则可能还有一个问题 - enable mod_rewrite

答案 1 :(得分:1)

确保在/etc/httpd/conf/httpd.conf(centos apache 2.2)中设置了AllowOverride All

config:

$config['index_page'] = '';