.htaccess - 在共享托管服务器上使用 codeigniter 感到困惑

标签 .htaccess codeigniter mod-rewrite

这对我来说是新的。我正在将我在 codeigniter 中创建的站点转移到 Godaddy 共享托管服务器。我可以通过以下方式进入主页:

http://www.example.com

但是当我尝试转到其他页面时,例如:
http://www.example.com/about-us/

它向我抛出此错误消息:

Not Found

The requested URL /example/index.php/about-us/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.



如果我使用:
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');

09-30-2011 更新:

在 .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 问题。尝试将您的 .htaccess 文件更改为:

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

关于.htaccess - 在共享托管服务器上使用 codeigniter 感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7615284/

相关文章:

php - 将参数传递给 Controller ​​的构造函数

php - codeigniter 中的产品详细信息页面路由

php - Laravel url 显示未找到错误

php - 提交表单时重写 url

codeigniter - 单击codeigniter中的下载按钮后将html转换为pdf

php - codeigniter 中的 Ajax 调用不像我预期的那样

apache - 未找到重定向匹配文件

wordpress - 谷歌搜索结果问题

php - Codeigniter Htaccess 和 URL 重定向问题

apache - 如何使用别名重写规则?