简体   繁体   English

强制从codeigniter中删除index.php

[英]force remove index.php from the codeigniter

This is my codeigniter .htaccess file, I was successful in replacing the index.php with method name. 这是我的codeigniter .htaccess文件,我成功地用方法名替换了index.php。 But I want to forcefully remove the index.php from the url ie if someone add index.php in the url i want to remove it using .htaccess. 但是我想从URL中强行删除index.php,即如果有人在URL中添加index.php,我想使用.htaccess将其删除。 Like=> http://localhost/project/index.php/welcome to=> http://localhost/project/welcome 喜欢=> http://localhost/project/index.php/welcome来到=> http://localhost/project/welcome

The project is still under development in xampp. 该项目仍在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>
<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>

Try this code : 试试这个代码:

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

and have a look to this article . 看看这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM