我发现了几个关于 CodeIgniter 和 mod-rewrite 问题的相关问题,但是,我还没有找到解决我目前遇到的问题的方法。
我目前有:mywebsiteurl.netfirms.com/mywebsite/index.php/admin/login
我想要实现的是从 URL 中删除 index.php,如下所示:mywebsiteurl.netfirms.com/mywebsite/admin/login
然而,在尝试了我在 StackOverflow 上找到的几个修复后,我最终偶然发现了一个不错的小指南,写在这里。
我已将我的 Mod-Rewrite 修改为如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(home(/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
即使在实施此 mod-rewrite 之后,如果我尝试访问 mywebsiteurl.netfirms.com/mywebsite/admin/login,我也会收到 404 错误。如果我去 mywebsiteurl.netfirms.com/mywebsite/index.php/admin/login 我可以加载页面就好了。
我的问题归结为如何正确配置 Code Igniter 的 mod 重写?也许我错过了一些设置?我对 mod-rewrite 不够熟悉,无法真正知道哪里出了问题。
我还应该提到我已经在我的 Code Igniter 配置文件中进行了更改。
$config['index_page'] = '';
有人对我在这里可能做错的事情有任何想法吗?
提前致谢。