3

我是CodeIgniter的新手,我开发了一个使用它的小网站。我的网站在 localhost中工作正常。但是当我将我的网站移动到Web服务器时,第一个Welcome控制器工作正常,因为我得到了我的第一个登录页面。当我点击我的登录(Welcome/login)。它提供了404 error(托管服务器404页面)。即使它没有给出任何验证错误。当我在服务器托管我的网站时出现404错误

我主持这个在一个子域(www.subdomain.example.com) 和我改变了base_url,就像这个域名。使用HTACCESS文件重写网址。

我将$index_page=“index.php”更改为$index_page=”“,用于从URL中删除index.php。 这在localhost中运行良好。在服务器上,我检查了$ index_page,然后它给出了CodeIgniter 404错误页面。

与我的本地主机的唯一区别是,我托管它在一个子域。这可能是问题.htaccess,它看起来像这样:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

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

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    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 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule>' 
+0

您需要提供更多信息。发布您的.htaccess文件,对于初学者,以及您尝试在主机上访问的路径(您说有一个子域)。 – regulatethis

+0

RTM - > http://ellislab.com/codeigniter/user-guide/general/urls.html – Sparky

回答

2

你更新你的.htaccess转发请求到index.php文件?你不能只将$ index_page设置为''。如果www.subdomain.example.com/index.php/Welcome/login出现,您可能只需将其添加到HTACCESS文件中:

RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA] 
+1

建议的话将永远不会使用大写的控制器名称或url期间的任何上限。 Linux操作系统区分大小写,而Windows操作系统不区分大小写。如果你在Windows上进行本地测试,你的urls可能会工作得很好,但是如果你把它推到Linux服务器上,你的urls很可能无法工作。要测试此尝试去www.subdomain.example.com/welcome/login – PhearOfRayne

+0

感谢您的answer.this网址是allso给404.i发布我的htaccess文件,你可以请检查它。 –

+0

您的新服务器是否启用了mod重写? – PhearOfRayne

相关问题