首页 文章

从CodeIgniter URL中删除index.php

提问于
浏览
2

我正在努力删除CodeIgniter URL的'index.php'部分 . 我正在使用CodeIgniter 3.1.2版 . 我已经对其他问题采取了所有步骤:

  • 已将 $config['index_page'] = 'index.php' 更改为 $config['index_page'] = ''

  • 已将 $config['uri_protocol'] = 'AUTO' 更改为 $config['uri_protocol'] = 'REQUEST_URI'

  • 使用以下代码在项目的根文件夹中添加了一个.htaccess文件:

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

但是,当我尝试访问我的网站时,我收到以下错误代码 .

未找到在此服务器上找不到请求的URL / Toneel / Site / index .

重写模块在我的Apache服务器中打开 . 任何人都可以帮我解决这个问题吗?

4 回答

  • 1

    这个设置对我有用 .

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

    的.htaccess

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

    要允许覆盖Apache配置中的htaccess,您必须编辑和更改 /apache2.conf 文件

    AllowOverride All
    

    并重启服务器 .

  • 0

    在.htaacess中尝试此代码:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$1 [PT,L]
    
  • 4

    在.htaccess文件中尝试此操作

    RewriteEngine On
    RewriteBase /yourfolderhere/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
  • 0

    就我而言,它适用于:

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /project-name
    
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ index.php [QSA,L]
    </IfModule>
    

    **重要的是,这应该位于项目根目录中的.htaccess文件中 .

    在配置中应该是这样的:

    $config['base_url'] = 'http://your-url-here/';
    $config['index_page'] = '';
    

相关问题