我多次测试我的网站,但我无法解决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&amp;第二个是inside.php,login.php包含登录表单,inside.php包含简单的html。
现在我的登录页面作为我网站的主页工作正常: http://localhost/website/Codeigniter_Project/MyProject/
当我执行以下操作时,我发现找不到页面错误: 我尝试了两种方式,两者都给了我同样的错误:
第一种方式:直接给出视图名称和结果页面未找到 本地主机/网站/ Codeigniter_Project / MyProject的/内
第二种方式:通过给出控制器名称然后查看但找不到结果页面 本地主机/网站/ Codeigniter_Project / MyProject的/ welcomelogin(controllername)/内
请帮助我,因为我花了将近2个小时通过搜索和应用不同的答案,是的,堆栈上有类似的问题,有些答案我已经尝试但没有工作&amp;那些问题与我的有点不同。谢谢你们的时间。:)我在localhost服务器上运行,我的apache mod_rewrite打开了。谢谢。 &安培;我是codeigniter的新手,谢谢
我的.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>
答案 0 :(得分:0)
请尝试使用此网址
http://localhost/website/Codeigniter_Project/MyProject/index.php/inside
希望如果您不限制url
与.htaccess
答案 1 :(得分:0)
PHP CI代码似乎很好,您应该检查.htaccess
文件,
当您添加有问题的.htaccess
文件时,您应该从您的网络目录添加RewriteBase
到项目主页,请参阅下面的示例代码
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>
答案 2 :(得分:0)
在我的情况下不需要任何修改只需要在路径中使用index.php文件,因此路径应该像这样http://localhost/website/Codeigniter_Project/MyProject/index.php/welcomelogin/inside
我通过教程找到了这个答案,我在研究时发现我的答案在线链接是http://tutorialcodeigniter.com/beginners/creating-controller.html - 有关如何从网址中删除 index.php 。最好的解释和工作 - Cannot remove index.php from CodeIgniter URL
但是,无论如何,还要感谢谁帮我查询。:)