【问题标题】:force remove index.php from the codeigniter强制从 codeigniter 中删除 index.php
【发布时间】:2013-07-19 14:01:03
【问题描述】:

这是我的 codeigniter .htaccess 文件,我成功地将 index.php 替换为方法名称。但我想从 url 中强制删除 index.php,即如果有人在 url 中添加 index.php,我想使用 .htaccess 删除它。 喜欢=> http://localhost/project/index.php/welcome to=> http://localhost/project/welcome

该项目仍在xampp开发中。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 

    # Enforce NO www
    RewriteCond %{HTTP_HOST} ^www [NC]
    RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
    </IfModule>

【问题讨论】:

    标签: php apache .htaccess codeigniter xampp


    【解决方案1】:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        #my url is http://localhost/project
        #RewriteBase /project/
        #set your own
        RewriteBase /project/
    
        #Redirect if index.php exist to without index.php
        RewriteRule ^index.php/(.*)$  $1 [R=301,L] 
    
        #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
        #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>
    

    【讨论】:

    • 谢谢,但是这个允许在 url 中使用 index.php。我想删除它。当有人键入 localhost/project/index.php/welcome 我希望 htaccess 自动将 index.php 删除到 localhost/project/welcome
    • 你可以同时使用。你否认 url 中的 index.php 并且只在没有 index.php 的情况下工作吗?
    • 更新了!请重试
    【解决方案2】:

    试试这个代码:

    RewriteEngine on
    RewriteBase /project/
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    看看this article

    【讨论】:

    • 对不起,这不是我要找的。我需要使用 .htaccess 强制删除 url 中的 index.php。
    • 是的。我明白。我的代码是一个 htaccess 代码。问题出在哪里?
    • 我编辑了我的代码。但我不明白为什么我的帖子没有回答你的问题。
    • 它被重定向到 localhost/xampp :/
    • 用我的替换你的整个代码,看看发生了什么。
    猜你喜欢
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2016-05-14
    • 2014-10-28
    • 2012-06-15
    • 2013-02-27
    • 2012-09-21
    相关资源
    最近更新 更多