【问题标题】:Trying to remove index.php from URL in codeigniter [duplicate]试图从 codeigniter 中的 URL 中删除 index.php [重复]
【发布时间】:2013-02-14 15:35:53
【问题描述】:

我正在尝试从 URL 中删除“index.php”。我已经尝试过制作

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

作为

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

$config['index_page'] = 'index.php';

作为

$config['index_page'] = '';

甚至尝试过放置

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]

在 .htaccess 文件中,但它对我不起作用。谁能告诉我哪里出错了? 提前谢谢..

【问题讨论】:

  • 你运行的是什么操作系统?视窗? Ubuntu?操作系统?

标签: codeigniter


【解决方案1】:

鉴于你告诉我你正在使用 Ubuntu...

  1. 使用 Ayman 提供的 .htaccess 配置。
  2. 打开终端并输入sudo a2enmod rewrite 以在您的计算机上启用mod_rewrite
  3. 使用sudo nano /etc/apache2/sites-enabled/000-default打开000-default并将AllowOverride None的第一次出现更改为AllowOverride All

然后用sudo service apache2 restart重启apache。

也可以使用:$config['index_page'] = '';

【讨论】:

  • 我知道它的格式不正确,但是很抱歉,我无法回答自己的问题,因为我没有 10 个声望
  • +1 现在你会的。欢迎来到 SO 并享受 CI。
【解决方案2】:

删除 index.php 有 3 个步骤

1.在 application/config.php 文件中进行以下更改

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2.使用以下代码在根目录中制作 .htacces 文件

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

3.启用重写模式

我。首先,使用以下命令启动它:

a2enmod 重写

二。编辑文件 /etc/apache2/sites-enabled/000-default

AllowOverride None 更改为 AllowOverride All

三。使用以下命令重新启动服务器:

sudo /etc/init.d/apache2 restart

【讨论】:

    【解决方案3】:

    得到答案,我刚刚在我的 .htaccess 文件中插入了以下代码:

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

    并制作 $config['index_page'] = '';

    config.php

    来源:Remove "index.php" from URL - Codeigniter‌​r

    回答者:@Akhilraj N S

    【讨论】:

      【解决方案4】:

      这是我经常使用的.htaccess 文件。为我工作:

      <IfModule mod_rewrite.c>
        DirectoryIndex index.php
        RewriteEngine on
        RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteBase /project/
        RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
      </IfModule>
      

      【讨论】:

      • 我应该将 .htaccess 文件与应用程序文件夹一起保存在应用程序文件夹还是主项目文件夹中?
      • 保存在主项目文件夹中
      • 它还在用index.php
      • .htaccess 文件应位于项目文件夹的根目录中。就在applicationsystem 旁边; 不在里面
      • $config['uri_protocol']改回AUTO
      猜你喜欢
      • 2020-08-12
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2012-09-21
      • 2011-10-12
      • 2017-07-16
      相关资源
      最近更新 更多