0

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

现在,当我尝试在 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]
4

3 回答 3

0

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

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

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

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

祝你好运。

于 2013-08-01T11:45:03.540 回答
0

这个 .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'] = '';
于 2013-08-01T12:32:35.553 回答
0

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

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
于 2013-08-01T11:42:49.183 回答