【问题标题】:how to remove index.php from url.eg. www.xyz.com/beta/index.php/home in codeigniter [duplicate]如何从 url.eg 中删除 index.php。 www.xyz.com/beta/index.php/home in codeigniter [重复]
【发布时间】:2021-01-22 02:53:01
【问题描述】:

我正在尝试 从 codeigniter 中的 url(子文件夹) 中删除 index.php。我正在尝试使用 htaccess 文件,但没有得到结果。

<IfModule mod_rewrite.c> 
    RewriteEngine On
    RewriteBase /
    RewriteCond $1 !^(index\.php) [NC]
    RewriteRule ^(.*)$ /beta/index.php/$1 [L]
</IfModule>

当我从 url 中删除 index.php 时,它会正常工作,但是当我尝试使用 url 跳转时,它将无法正常工作,并且 index.php 不会从 URL 中自动删除。

提前致谢。

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    从 URL 中隐藏 index.php。将此代码放入 .htaccess 文件中。

    mod_rewrite 必须使用 PHP 启用

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

    您可能还需要根据您的托管服务提供商添加此内容:

     RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
    

    或者转到 application/confing 并将此行更改为:

     //find the below code   
     $config['index_page'] = "index.php" 
     //replace with the below code
     $config['index_page'] = ""
    

    【讨论】:

    • 感谢您的回答。我正在尝试您的代码,但它不会被删除。
    • 第二种方法你试过了吗?
    【解决方案2】:
    RewriteEngine On
    RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
    

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。
    猜你喜欢
    • 2013-05-09
    • 2020-08-12
    • 2013-08-02
    • 2014-09-20
    • 1970-01-01
    • 2012-08-10
    • 2015-10-24
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多