编码器2:请求的URL在此服务器上找不到(404)错误.CI没有选择正确的路由方式


Codeigniter 2: The requested URL was not found on this server (404) error. CI isn't routing the right way

这是最常被问到的问题之一,但我不明白,不得不问。我使用CI 2。我通过以下步骤从URL中删除了index.php:

  1. config.php I设置

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
  1. 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
  1. 我在web服务器上启用了mod_rewrite

所以在InterviewControllerindex()方法中,我加载addInterview.php视图。之后,当我输入域名时,它被称为addInterview作为网站的默认页面。当我按下addInterview页面上的保存按钮时,必须从InterviewController调用saveInterview()。但在这一步我得到The requested URL was not found on this server (404) errorsaveInterview()甚至还没有被调用。但是,如果我自己键入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]