我是CodeIgniter的新手,因此我使用它开发了一个小型网站。我的网站在localhost
。但是,当我将网站移至Web服务器时,第一个Welcome Controller 可以正常工作,因为我获得了第一个登录页面。当我单击我的登录名(Welcome/login
)时。它给出了404 error
(托管服务器404页面)。即使没有任何验证错误。
我将其托管在一个子域中(www.subdomain.example.com
)
然后我更改了base_url,就像这个域名一样。使用HTACCESS
文件重写URL。
我将$index_page=“index.php”
更改为$index_page=”“
,以从URL中删除index.php。
这在本地主机上运行良好。在我用$ 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>'
最佳答案
您是否更新了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]
关于codeigniter - 当我将网站托管在服务器中时出现404错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13898290/