我需要从我的codeigniter网址中删除index.php . 这是我在.htaccess文件中的代码:
RewriteEngine On
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
和config.php文件中的修改:
$config['base_url'] = 'http://example.com/'
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我的localhost工作正常 . 但在我的实时网站中,它会产生404错误 .
我可以用index.php加载网址('http://example.com/index.php/Home '), but ' http://example.com/Home'生成404错误 . 为什么这只发生在实际网站?是否还需要其他更改?还有一件事,它不是apache服务器,我的网站是在iis中发布的
3 回答
将以下代码粘贴到.htaccess文件中
然后转到config文件夹中的配置文件并从中删除index.php
如果您的站点位于子文件夹中,则必须在“#RewriteBase /”之后添加子文件夹名称
我想你错过了
这是完整的htaccess,它应该驻留在主项目文件夹中 . 如果它位于子文件夹中,则必须编写重写库 .