Codeigniter-出现404找不到错误 [英] Codeigniter - getting 404 Not Found error

查看:88
本文介绍了Codeigniter-出现404找不到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在godaddy拥有两个托管包。使用以下.htaccess文件,我们的实时网站正常运行。可访问网站,而无需在URL中使用index.php。

We have two hosting packages at godaddy. Our live website is working fine using following .htaccess file. Website is accessible without using index.php in url.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L] 

我们在godaddy的其他主机上使用了相同的htaccess文件和相同的代码。我们只是想将生产和开发实例分开。但是在其他具有相同代码和htaccess文件的主机上,网站显示404页面未找到错误,但网站在url中使用index.php可以正常工作。

We used same htaccess file and same code on other hosting that is also by godaddy. We just wanted to make production and development instances seperate. But on other hosting with same code and htaccess file, website shows 404 page not found error but website works fine with index.php in url.

我们在相同的php版本上两个服务器。只是想知道可能是什么问题?

We have same php version on both server. Just wants to know what could be the issue?

推荐答案

将100%工作代码移至专用的Debian服务器。经过3个小时的研究,我发现了htaccess文件无法正常工作的原因。您需要在Apache配置中允许覆盖htaccess。

I also faced the similar problem when I move my 100% working code to dedicated Debian server. After 3 hours of research, i found out why htaccess file is not working.You need to allow overriding of htaccess in Apache Configuration.

以下是步骤。

步骤1:

将此文件添加到htaccess文件中

Add this in htaccess file

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

步骤2:

在codeigniter配置中删除index.php

Remove index.php in codeigniter config

$config['index_page'] = '';

步骤3:

在Apache配置中允许覆盖htaccess(命令)

Allow overriding htaccess in Apache Configuration (Command)

sudo nano /etc/apache2/apache2.conf

并编辑文件&更改为

and edit the file & change to

AllowOverride All

用于www文件夹

步骤4:

重新启动Apache(命令)

Restart Apache (Command)

sudo /etc/init.d/apache2 restart

在apache2.conf文件中进行任何更改之前,请确保对该文件进行备份。如果您使用的是Debian服务器,则可以避免使用sudo命令。我相信您知道如何使用类似腻子的ssh客户端软件连接到服务器。如果此方法不适合您,请在下面评论。

Before you make any changes in apache2.conf file make sure to make a backup copy of that file. If you are using Debian server you can avoid sudo command. I believe you know how to connect to your server using ssh client software like putty. Comment below if this method does not work for you.

这篇关于Codeigniter-出现404找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆