php Codeigniter 2:在此服务器上找不到请求的 URL (404) 错误。CI 的路由方式不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15492446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:20:39  来源:igfitidea点击:

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

phpcodeigniterviewroutingurl-routing

提问by Factory Girl

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:

这是最重复的问题之一,但我没有得到它,不得不问。我使用 CI 2。我通过以下步骤从 URL 中删除了 index.php:

  1. In config.phpI set
  1. config.php我设置

$config['index_page'] = '';

$config['uri_protocol'] = 'REQUEST_URI';
  1. In routes.phpI set
  1. routes.php我设置

$route['default_controller'] = "InterviewController";
  1. here is my .htaccess
  1. 这是我的 .htaccess

RewriteEngine on
RewriteCond  !^(index\.php|img|robots\.txt|css|js|libraries/ckeditor|upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]
addDefaultCharset UTF-8
  1. I enabled mod_rewriteon the web server.
  1. mod_rewrite在网络服务器上启用。

So in the index()method of InterviewController, I load the addInterview.phpview. After that, it is being called addInterviewas the default page of the site when I type just the domain name. Problem occurs when I press Save button on addInterviewpage 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.phpjust from default page, but not from all pages of my site. What do you recommend?

所以在 的index()方法中InterviewController,我加载了addInterview.php视图。之后,addInterview当我只输入域名时,它被称为站点的默认页面。当我在addInterview必须saveInterview()InterviewController. 但是在这一步中我得到了The requested URL was not found on this server (404) error. saveInterview()甚至没有被调用。但是如果我自己输入 domainname/index.php/InterviewController/saveInterview 一切正常。似乎我index.php只是从默认页面中删除,而不是从我网站的所有页面中删除。你有什么建议吗?

回答by Mike Rockétt

The leading slash could be causing your problem.

前导斜杠可能会导致您的问题。

Change

改变

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

to

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

回答by User

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?/ [L] 

回答by Welcome Always

edite your .htaccess file to>

将您的 .htaccess 文件编辑为>

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

回答by Amit Horakeri

Change the rewrite rule to

将重写规则更改为

##代码##