这是最常被问到的问题之一,但我不明白,不得不问。我使用CI 2。我通过以下步骤从URL中删除了index.php:
- 在
config.php
I设置
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
-
routes.php
I设置
$route['default_controller'] = "InterviewController";
- 这是我的。htaccess
RewriteEngine on
RewriteCond $1 !^(index.php|img|robots.txt|css|js|libraries/ckeditor|upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
addDefaultCharset UTF-8
- 我在web服务器上启用了
mod_rewrite
。
所以在InterviewController
的index()
方法中,我加载addInterview.php
视图。之后,当我输入域名时,它被称为addInterview
作为网站的默认页面。当我按下addInterview
页面上的保存按钮时,必须从InterviewController
调用saveInterview()
。但在这一步我得到The requested URL was not found on this server (404) error
。saveInterview()
甚至还没有被调用。但是,如果我自己键入domainname/index.php/InterviewController/saveInterview一切工作。似乎我删除了index.php
只是从默认页面,但不是从我的网站的所有页面。你有什么建议吗?
前面的斜杠可能会导致您的问题。
改变RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ index.php [L]
试试这个…
RewriteEngine on
RewriteBase /Ur_Folder_Path/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Ur_Folder_Path/index.php?/$1 [L]
编辑你的。htaccess文件到>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
将重写规则更改为
RewriteRule ^(.*)$ /YOUR_CI_PROJECT_NAME/index.php/$1 [L]