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

*爱你&永不变心* 提交于 2019-12-31 03:43:07

问题


This is one of the most repeated questions, but I did not get it and had to ask. I use CI 2. I removed index.php from URL by following steps:

  1. In config.php I set

$config['index_page'] = '';

$config['uri_protocol'] = 'REQUEST_URI';
  1. In routes.php I set

$route['default_controller'] = "InterviewController";
  1. here is my .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. I enabled mod_rewrite on the web server.

So in the index() method of InterviewController, I load the addInterview.php view. After that, it is being called addInterview as the default page of the site when I type just the domain name. Problem occurs when I press Save button on addInterview page which must call saveInterview() from InterviewController. But in this step I get The requested URL was not found on this server (404) error. saveInterview() even hasn't been called. But if I myself type domainname/index.php/InterviewController/saveInterview everything works. Seems like I removed index.php just from default page, but not from all pages of my site. What do you recommend?


回答1:


The leading slash could be causing your problem.

Change

RewriteRule ^(.*)$ /index.php/$1 [L]

to

RewriteRule ^(.*)$ index.php [L]



回答2:


try this...its Working for me

RewriteEngine on
RewriteBase /Ur_Folder_Path/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Ur_Folder_Path/index.php?/$1 [L] 



回答3:


edite your .htaccess file to>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>



回答4:


Change the rewrite rule to

RewriteRule ^(.*)$ /YOUR_CI_PROJECT_NAME/index.php/$1 [L]


来源:https://stackoverflow.com/questions/15492446/codeigniter-2-the-requested-url-was-not-found-on-this-server-404-error-ci-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!