0

This is my codeigniter .htaccess file, I was successful in replacing the index.php with method name. But I want to forcefully remove the index.php from the url i.e if someone add index.php in the url i want to remove it using .htaccess. Like=> http://localhost/project/index.php/welcome to=> http://localhost/project/welcome

The project is still under development in 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>

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

3 Comments

thanks, but this one allows index.php in the url. I want to remove it. when ever someone types localhost/project/index.php/welcome i want the htaccess to automatically remove index.php to localhost/project/welcome
You can use both way. Dou you deny index.php in url and only works without index.php?
Updated! Please try again
0

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.

7 Comments

sorry it's not what i am looking for. I need to forcefully remove the index.php in the url using .htaccess.
Yes. I understand. My code is an htaccess code. Where is the problem ?
I edited my code. But i don't understand why my post doesn't answer to your question.
it's getting redirected to localhost/xampp :/
Replace your whole code with mine, just to see what it is happened.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.