【问题标题】:Puzzled using codeigniter on shared hosting server在共享托管服务器上使用 codeigniter 感到困惑
【发布时间】:2011-11-28 17:45:56
【问题描述】:

这对我来说是新的。我正在将我在 codeigniter 中制作的网站转移到 godaddy 共享托管服务器。我可以通过以下方式访问主页:

http://www.example.com

但是当我尝试转到其他页面时:

http://www.example.com/about-us/

它向我抛出此错误消息:

找不到

在此服务器上找不到请求的 URL /example/index.php/about-us/。

此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

如果我使用:

http://www.example.com/index.php/about-us/

页面清晰如初。

我查找了 CI 解决方法,但我的网站更多的是静态页面而不是动态页面。

总的来说,我的问题是,我做错了什么,这与拥有 Godaddy 共享主机帐户有什么关系?

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

CI 配置文件

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';

CI 自动加载文件

$autoload['helper'] = array('url');

2011 年 9 月 30 日更新:

在.htaccess中使用:

# Options
Options -Multiviews
Options +FollowSymLinks

#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /

#Removes access to CodeIgniter 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

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L]  

在 CI 配置文件中:

$config['index_page'] = ""; 
$config['uri_protocol'] = "AUTO"; 

来源:codeigniter.com/wiki/Godaddy_Installaton_Tips

【问题讨论】:

  • 不要在标题或问题中加上“已解决”或类似的字眼。请改为在下面发布您的解决方案作为答案。谢谢。

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

您更新的 .htaccess 是正确的。你需要对它做一点小改动。 在.htaccess 文件中更改以下行:

 RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

在你的config.php

$config['uri_protocol'] = 'QUERY_STRING';

【讨论】:

    【解决方案2】:

    这不是一个很好的解决方案,但在我的 WAMP 本地主机上出现同样的错误......

    我对此有一个简单的修复,它在我升级我的 WAMPserver 后开始出现。它设置了一个新的 apache 配置并关闭了 rewrite_module。

    要修复,我只需左键单击 wamperver 图标->Apache->Apache Modules->rewrite_module 并确保已勾选。

    【讨论】:

      【解决方案3】:

      这是一个 .htaccess 问题。尝试将您的 .htaccess 文件更改为:

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

      【讨论】:

      • 嗯。尝试查看这篇文章 (codeigniter.com/wiki/Godaddy_Installaton_Tips) 和相关讨论 (codeigniter.com/forums/viewthread/133292)。 2011 年的一些帖子可能会有所帮助。
      • 另外,请尝试在RewriteEngine on 之后的新行中添加Options +FollowSymLinks
      • 如果您从我的链接中找到它,您可以投票或接受我的回答吗?如果您没有,请在此处发布解决方案,以便其他人可以看到。谢谢:)
      猜你喜欢
      • 2014-03-19
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      相关资源
      最近更新 更多