我是CodeIgniter的新手,我开发了一个小网站。我的网站工作正常
localhost
。但当我将我的网站移动到Web服务器时,第一个欢迎控制器工作正常,因为我得到了我的第一个登录页面。当我点击我的登录信息(Welcome/login
)时。它给出404 error
(托管服务器404页面)。即使它没有给出任何验证错误。
我将其托管到子域(www.subdomain.example.com
)
我更改了base_url,就像这个域名一样。使用HTACCESS
文件重写网址。
我将$index_page=“index.php”
更改为$index_page=”“
,以便从URL中删除index.php。
这在localhost中运行良好。在我用$ index_page检查的服务器上,它给出了CodeIgniter 404错误页面。
与我的localhost的唯一区别是,我将其托管在子域中。这可能是.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 :(得分: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]