Php Codeigniter-获取404未找到错误
我们在godaddy有两个主机包。我们的live网站使用以下.htaccess文件运行良好。网站无需在url中使用index.php即可访问Php Codeigniter-获取404未找到错误,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我们在godaddy有两个主机包。我们的live网站使用以下.htaccess文件运行良好。网站无需在url中使用index.php即可访问 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 我们在godaddy提供的其他主机上使用了相同的htaccess文件和相同的代码。我们只是想将生产和开
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
我们在godaddy提供的其他主机上使用了相同的htaccess文件和相同的代码。我们只是想将生产和开发实例分开。但在使用相同代码和htaccess文件的其他主机上,该网站显示404页面未找到错误,但该网站在url中使用index.php可以正常工作
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
我们在两台服务器上都有相同的php版本。只是想知道问题出在哪里?当我将100%的工作代码转移到专用Debian服务器时,我也遇到了类似的问题。经过3个小时的研究,我发现了htaccess文件无法工作的原因。您需要允许在Apache配置中覆盖htaccess 以下是步骤 第1步: 将此添加到htaccess文件中
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
第三步:
允许在Apache配置中覆盖htaccess(命令)
并编辑该文件&更改为
AllowOverride All
www文件夹
第4步:
重新启动Apache(命令)
在对apache2.conf文件进行任何更改之前,请确保备份该文件。如果您使用的是Debian服务器,则可以避免使用sudo命令。我相信您知道如何使用ssh客户端软件(如putty)连接到服务器。如果此方法不适用于您,请在下面进行评论。我对服务器联网的知识有限,但这应该会给您一些想法 首先,您必须知道.htacess文件是什么。你可以在这里查一下 .htaccess是一个配置文件,用于运行 Apache Web服务器软件。将.htaccess文件放置在 目录,该目录依次“通过Apache Web服务器加载”,然后 .htaccess文件由Apache Web服务器检测并执行 软件。这些.htaccess文件可用于更改配置 使用Apache Web服务器软件来启用/禁用其他 Apache Web服务器软件必须具备的功能和特性 提供这些功能包括基本的重定向功能,例如 如果发生404文件找不到错误,或对于更高级的 内容密码保护或图像热链接等功能 预防 基本上,htaccess允许您编辑apacheweb服务器的配置。如果在Apache中启用了mod_rewrite,您将使用.htacess获得权限。我不会写.htaccess中的4个基本行在codeigniter中可以做什么,因为您可以在google中找到它。这可以给你一些很好的基本信息 现在的主要问题是.htaccess在您的其他主机中不起作用。这是可能的,因为以下几个原因:
检查并签入“已加载的模块”,以确定模块重写是否存在。这个例子我希望这能澄清您对.htaccess不起作用的困惑。您可以使用它。这对我在godaddy的主持很有效
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
当我使用godaddy服务器时,我也遇到过类似的问题。这对我来说是个好办法 将此代码添加到.htaccess文件中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
并在httpd.conf中将AllowOverride设置为All
在/cache文件夹上设置正确的权限,而不仅仅是使文件夹可写—您需要使其隐秘可写
我希望它能为您工作。在index.php中,您回显“test”并运行。然后您可以检查它是否被调用。
在配置文件中启用错误日志。
使/application/logs文件夹可写。
在/application/config/config.php中设置<代码>$config['log_threshold']=4代码>
检查日志/application/logs
文件夹尝试将所有控制器小写。这个可以帮我解决问题。试试这个。。这对我很有用
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
照此
- 在public\u html/Project root中创建一个新的.htaccess文件
- 粘贴以下代码
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]
- 可选的
如果可以使用命令ssh将ssh连接到服务器username@ip_address
在Linux终端或Putty命令行上
用户名是GoDaddy提供给您的,您也可以使用root
ip\u地址
将是主机的公共ip,您可以在主机面板中找到它
运行命令sudo a2dispate 000 default
该命令禁用处理请求的默认apache配置
祝你好运 正如您在这里提到的,在localhost上,您的代码工作正常,但当您将其移动到live server上时,会导致404错误。您可能需要检查的情况很少:
$config['base_url'] = 'domain.com';
$config['index.php'] = '';
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]
<?php
echo 'Test'; die;
?>