【发布时间】: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";
【问题讨论】:
-
不要在标题或问题中加上“已解决”或类似的字眼。请改为在下面发布您的解决方案作为答案。谢谢。
标签: .htaccess codeigniter mod-rewrite