CodeIgniter没有';无法在服务器上正确显示网站


CodeIgniter doesn't display website properly on server

我使用CodeIgniter框架在PHP中创建了一个站点。完成后,我编辑了routes.php文件并添加了.htaccess文件以从URL中删除/index.php/部分。

现在,当我尝试在localhost中打开它时,它运行良好,我可以访问http://localhost/mysite并获得我想要的登录页。

但是,问题是当我试图访问服务器上的网站时,我会遇到一个错误。所以,如果我打开类似http://mysite.com的东西,我会得到CodeIngniters默认的404页面。如果我指定了他们的URL,我可以打开所有其他页面,比如:http://mysite.com/about,但当其他人打开网站时,他会收到一个错误,他不知道该键入什么来忽略这个错误。

我该怎么办才能解决这个问题?提前谢谢。

编辑:.htaccess

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

这个.htaccess代码总是对我有效,你可以试试这个:

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

您的.htaccess确实引起了一些问题,您正试图将文件位置作为查询字符串传递,这可能在CodeIgniter中起作用,但有更好的方法可以做到这一点。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]

此外,请确保在config.php中设置了以下选项:

$config['uri_protocol'] = 'REQUEST_URI';

祝你好运。

此.htaccess代码适用于

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

配置

$config['index_page'] = '';
相关文章: