我测试了我的网站很多次,但我无法解决Page not found错误。嗯,
1步:我创建了一个控制器,并调用welcomelogin.php-在那里我存储了两个函数
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class WelcomeLogin extends CI_Controller {
public function index()
{
$this->home();
}
public function home(){
$this->load->helper('url');
$this->load->view('login');
}
public function inside(){
$this->load->helper('url');
$this->load->view('inside');
}
2-步骤:在我的rote.php文件中,我简单地执行以下操作:
$route['default_controller'] = "welcomeLogin";
$route['404_override'] = '';
3-步骤:在视图文件夹中,我创建了两个文件,一个是login.php&第二个是inside.php,login.php包含登录表单,inside.php包含简单的html。
现在我把登录页面作为我网站的主页,它运行得很好:http://localhost/website/Codeigniter_Project/MyProject/
当我执行以下操作时,我得到页面未找到错误:我尝试了两种方法,但都给了我相同的错误:
第1种方式:直接给出视图名称和未找到的结果页localhost/website/Codeigner_Project/MyProject/内部
第二种方式:提供控制器名称,然后查看,但未找到结果页localhost/website/Codeigner_Project/MyProject/welcomelogin(controllername)/inder
请帮助我,因为我花了将近2个小时来搜索和应用不同的答案,是的,堆栈上有类似的问题,有些问题的答案我已经尝试过了,但没有成功;那些问题和我的有点不同。谢谢你们抽出时间。:)我在localhost服务器上运行,我的apachemod_rewrite已打开。谢谢&感谢,我是代码点火器的新手
我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/Codeigniter_Project/MyProject/
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
请尝试使用此url
http://localhost/website/Codeigniter_Project/MyProject/index.php/inside
如果您不使用.htaccess
限制url
的流量,希望这将起作用
PHP CI代码似乎很好,您应该检查.htaccess
文件,
当您添加有问题的.htaccess
文件时,您应该将RewriteBase
从web目录添加到项目主页,请参阅下面的示例代码
RewriteBase /website/Codeigniter_Project/MyProject/
更新的htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
########### TODO: deploying on subdir must rewrite this
RewriteBase /website/Codeigniter_Project/MyProject/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
# you could simply throw this into an htaccess file the directory you want displayed
Options -Indexes
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
在我的情况下不需要任何修改,只需要在路径中使用index.php文件,所以路径应该是这样的http://localhost/website/Codeigniter_Project/MyProject/index.php/welcomelogin/inside
我通过一个教程找到了这个答案,我在研究我的答案时发现了在线链接http://tutorialcodeigniter.com/beginners/creating-controller.html-了解如何从url中删除index.php。最好的解释和工作对我来说-无法从CodeIgniter URL 中删除index.php
但无论如何,感谢那些试图帮助我查询的人。:)