首页 文章

无法从实时网站中的codeigniter网址中删除index.php

提问于
浏览
-1

我需要从我的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 回答

  • 0

    将以下代码粘贴到.htaccess文件中

    RewriteEngine On
       #RewriteBase /
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule (.*) index.php/$1
    

    然后转到config文件夹中的配置文件并从中删除index.php

    $config['index_page'] = '';
    

    如果您的站点位于子文件夹中,则必须在“#RewriteBase /”之后添加子文件夹名称

  • 0

    我想你错过了

    RewriteBase /

  • 0

    这是完整的htaccess,它应该驻留在主项目文件夹中 . 如果它位于子文件夹中,则必须编写重写库 .

    <IfModule mod_rewrite.c>
      RewriteEngine On
      # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
      #  slashes.
      # If your page resides at
      #  http://www.example.com/mypage/test1
      # then use
      # RewriteBase /mypage/test1/
      RewriteBase /
      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>
    

相关问题