3

I know this question has been asked a number of times. However, I still wasn't able to get rid of index.php url. It is preventing me to access my controller directly.

I am current using CodeIgniter 2.2.2.
And the following is my .htaccess file:

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

application/config:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

Any Idea? Thanks in advance for your time.

2
  • Are you using wamp or xampp? Commented Feb 5, 2016 at 4:52
  • 1
    I am using wamp right now, but currently I would like to be able to access in production as well. (Prod currently running linux apache) Commented Feb 5, 2016 at 10:07

8 Answers 8

1

Use below code in your .htacess

   DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

Comments

1

try this..

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Comments

1

i had the same problem before. this is what i did

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

then go to config.php and remove the index.php

$config['index_page'] = 'index.php';
//change it to
$config['index_page'] = '';

Comments

1

If your using wamp make sure you have apache mod rewrite enabled.

This htaccess is good for wamp or xampp

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

Make sure it is placed on the main directory.

$config['index_page'] = '';

Comments

1

From the CI User Manual:

Index.php file will be included as default in your URLs.

Example:

example.com/index.php/controller

How can you change?

You can use rewrite rule in .htaccess for removing index.php from the URLs

Example from User Guide:

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

Using the "negative" method in which everything is redirected except the specified items.

One last thing make you are using index_page as empty location application/config/config.php:

$config['index_page'] = '';

In last if you are still facing issue change uri_protocol AUTO to REQUEST_URI.

$config['uri_protocol'] = "REQUEST_URI";

3 Comments

@wolfgang1983 got it bro
I looked at this guide before, didn't help.
@cs-learning-101 also change $config['uri_protocol'] = "REQUEST_URI"; if its auto
0

This worked for me.

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

Comments

0

on your .htaccess

RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

and $config['index_page'] = '';

worked for me

Comments

-1

Finally fixed my problem. I would like to share my answer to all of you. I am currently using a mac, my rename my .htaccess file into htaccess.txt And had the following code inside htaccess: RewriteEngine On

#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 %{ENV:REDIRECT_STATUS} ^$
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

Then make sure Apache is reading the htaccess.txt file by doing this:

  1. Uncomment the following line on your httpd.conf

  2. Go inside to the extra/httpd-default.conf file and change this line of code: AccessFileName .htaccess to AccessFileName htaccess.txt

  3. Restart Apache server

  4. Inside your config, make sure to leave 'base_url' empty (index page can still be there, doesn't matter). And $config['uri_protocol'] = 'REQUEST_URI';

Hope this can help others out there!

Comments

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.