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
Codeigniter 2: The requested URL was not found on this server (404) error. CI isn't routing the right way
提问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:
- In
config.phpI set
- 在
config.php我设置
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
- In
routes.phpI set
- 在
routes.php我设置
$route['default_controller'] = "InterviewController";
- here is my .htaccess
- 这是我的 .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
- I enabled
mod_rewriteon the web server.
- 我
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
将重写规则更改为
##代码##
