【问题标题】:Remove index.php? from URL with question mark | Codeigniter删除 index.php?来自带问号的 URL |代码点火器
【发布时间】:2021-09-25 08:39:42
【问题描述】:

嗨,亲爱的 Stackflow 社区,我是 Codeignite 编码的新手,所以我希望你们给我时间来解决这个错误,谢谢提前 :) 所以基本上我在这里遵循了一个教程,我从 URL 禁用了 index.php,该问题已解决,但我仍然有剩余的问号?我在stackflow中尝试了每个教程,最终我设法删除了index.php,但问号仍然存在,那么如何删除index.php?最后有 example.com/index.php?/signin 到 example.com/signin 没有 index.php 和?标记 这是我的 htaccess 文件夹

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
</IfModule>
AddType text/vtt .vtt

【问题讨论】:

    标签: .htaccess codeigniter url


    【解决方案1】:

    不幸的是,这个问题可能高度依赖于您的 Apache 配置和您的网络主机配置。

    这段代码尝试了一种稍微不同的方法,并且更积极地找出额外的 ?和 /。它还将摆脱无限重定向,这取决于您的服务器配置。

        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
    
        RewriteCond %{ENV:REDIRECT_STATUS} ^$
        RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
    
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^ - [L]
    

    【讨论】:

    • 我在我的 htaccess 中试过了,index.php 不见了,但问号?剩下的请帮帮我
    【解决方案2】:

    试试这个:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    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>
    

    或者简单的版本:

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

    【讨论】:

    • 我在 htaccess 中都试过了,现在你的代码也是同样的问题 index.php 又回来了,它显示像这样 example.com/index.php?/
    • 您需要通过删除 index.php 来更新 config 文件夹中的 config.php。 $config['index_page'] = '';
    猜你喜欢
    • 2014-01-15
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 2021-10-16
    相关资源
    最近更新 更多