Codeigniter 2: The requested URL was not found on

2019-03-02 10: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?

4条回答
对你真心纯属浪费
2楼-- · 2019-03-02 10:19

Change the rewrite rule to

RewriteRule ^(.*)$ /YOUR_CI_PROJECT_NAME/index.php/$1 [L]
查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-02 10:20

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] 
查看更多
唯我独甜
4楼-- · 2019-03-02 10:30

The leading slash could be causing your problem.

Change

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

to

RewriteRule ^(.*)$ index.php [L]
查看更多
你好瞎i
5楼-- · 2019-03-02 10:43

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>
查看更多
登录 后发表回答