服务器移动后,codeigniter站点返回404错误

时间:2014-03-12 18:31:07

标签: php .htaccess codeigniter http-status-code-404

我正在将现有的codeigniter网站从MediaTemple共享服务器移动到Dreamhost VPS服务器。我已经设置了新服务器的镜像,无需切换DNS即可查看该站点;你可以看到它here

我试图切换DNS,但问题仍然存在。

如您所见,它返回404错误。如果我删除htaccess文件,将出现主页,但没有一个html页面可以正常工作。我认为这与htaccess文件中的RewriteCond和RewriteRule语句有关。

这是htaccess文件:

AddHandler php-stable .php
php_flag allow_url_fopen on
# php_flag extension_dir=/home/86983/data/lib/php
# php_flag extension=zip.so


Options +FollowSymLinks
RewriteEngine on

# RewriteCond $1!^(js|css|images|license\.txt|user_guide|admin|phpMyAdmin|uploads|ornaments_sitemap2_25_09\.xml|sitemap\.xml|robots\.txt|quickscript\.php|paypal_ipn\.php|test\.php|sitedown\.php)
# RewriteRule ^(.*)$ http://www.ornaments.com/sitedown\.php [L]

RewriteCond %{HTTP_HOST} ^ornaments\.com$ [NC]
RewriteRule (.*) http://www.ornaments.com/$1 [R=301,L]

RewriteCond $1 !^(admin|backupForPhpMyAdmin|blog|change_page_name\.php|css|favicon\.ico|images|index\.php|js|license\.txt|ornaments_sitemap2_25_09\.xml|paypal_ipn\.php|phpMyAdmin|uploads|quickscript\.php|robots\.txt|sitemap\.xml|sub-domains|test\.php|testblog\.php|url_checker|user_guide|tinymy\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

# RewriteCond %{HTTP_HOST} ^s86983\.gridserver\.com$ [NC]
# RewriteRule (.*) http://www.s86983\.gridserver.com/$1 [R=301,L]
# 
# RewriteCond $1 !^(blog|index\.php|js|css|images|license\.txt|user_guide|admin|phpMyAdmin|uploads|ornaments_sitemap2_25_09\.xml|sitemap\.xml|robots\.txt|quickscript\.php|paypal_ipn\.php|test\.php|backupForPhpMyAdmin)
# RewriteRule ^(.*)$ /index.php/$1 [L]

注意:我没有构建这个站点,只是略微熟悉codeigniter和PHP。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我建议你复制一下htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
</IfModule>

<IfModule !mod_rewrite.c>
    #LoadModule rewrite_module modules/mod_rewrite.c
    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php
</IfModule>

答案 1 :(得分:0)

我们通过将htaccess文件替换为有效网站的openCart部分来解决这个问题。那个文件看起来像这样:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule sitemap.xml /index.php?route=feed/google_sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) /index.php?_route_=$1 [L,QSA]



### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
#php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
#php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.shop.ornaments.com [NC]
RewriteRule ^(.*)$ http://shop.ornaments.com/$1 [R=301,L]

我不清楚为什么它能起作用,还有什么可能仍然被打破,我们还看不到,但到目前为止看起来还不错。