【问题标题】:How can remove index.php from url [duplicate]如何从 url 中删除 index.php [重复]
【发布时间】:2013-02-22 05:25:14
【问题描述】:

当我将鼠标悬停或单击锚链接时,它会显示

http://localhost/code-testing/index.php/about-us. 

我也试过 base_url() 和 site_url() 但结果是一样的。我怎样才能从 url 中删除那个 'index.php' ?

-谢谢。

已解决:

感谢大家的友好回答。我正在使用 xampp,这个对我有用

代码测试/应用程序/config/config.php

$config['base_url']= 'http://localhost/code-testing/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

代码测试/.htaccess

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

然后以下链接可以正常工作,而不会在 url 中显示“index.php”

<li><a href="<?php echo base_url('home');?>">HOME</a></li>
<li><a href="<?php echo base_url('about_us');?>">About Us</a></li>
<li><a href="<?php echo base_url('contact');?>">Contact Us</a></li>

【问题讨论】:

  • 但很抱歉,该帖子没有显示完整的方法。因为没有说 $config['uri_protocol'] = '?'; 应该写什么在 config.php 中,所以我没明白。

标签: codeigniter url


【解决方案1】:

删除 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

【讨论】:

  • 感谢您的回答。你的解决方案也有效。
  • @user1844626:欢迎哥们
【解决方案2】:

将变量设置为空,如下所示。

$config['index_page'] = '';

尝试用这些参数('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO')一一替换以下变量

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

【讨论】:

    【解决方案3】:

    在应用程序根目录中拥有 .htaccess 文件以及 index.php 文件。 (检查 htaccess 扩展是否正确,Bz htaccess.txt 对我不起作用。)

    并将以下规则添加到 .htaccess 文件中,

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

    然后在您的 application/config/config.php 文件中找到以下行

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

    将变量设置为空,如下所示。

    $config['index_page'] = '';
    

    就是这样,它对我有用。

    如果它不起作用,请尝试用这些参数('AUTO'、'PATH_INFO'、'QUERY_STRING'、'REQUEST_URI'和'ORIG_PATH_INFO')一一替换以下变量

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

    【讨论】:

      猜你喜欢
      • 2015-12-14
      • 2011-11-10
      • 2020-08-12
      • 2012-05-15
      • 1970-01-01
      • 2018-02-09
      相关资源
      最近更新 更多