1

I tried to remove index.php from my url in codeigniter i tried by creating with .htaccess file but it does not works.

RewriteEngine on
RewriteBase /
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

I tried by using this code and also these are mu bse and site url.I not have much knowledge that how to use htaccess properly.Any help is appreciable.

$config['base_url'] = 'http://localhost/xxxx/';

$config['site_url'] = 'http://localhost/xxxx/index.php';
1
  • just replace RewriteRule ^(application|system|\.svn) index.php/$1 [L] with RewriteRule ^(.*)$ index.php?/$1 [L] Commented Apr 7, 2018 at 5:59

4 Answers 4

4

Open config.php and do following replaces

From:

$config['index_page'] = "index.php";

To:

$config['index_page'] = "";

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

Add in .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
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.

1 Comment

I tried using this also but error in url an extra '/' is appearing in the place of index.php.
2

Hope this will help you :

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

and also set your config.php:

    $config['index_page'] = '';
    $config['base_url'] = 'http://localhost/foldername/';

for more : https://www.codeigniter.com/user_guide/general/urls.html

9 Comments

I had one doubt where should i place this htaccess file should i keep it in system folder or just outside application folder.
just outside your application folder means within your app folder
should i remove index.php from my site_url.
no need to worry about that just use base_url() or site_url() as it is
ok by using this index.php is removed but url is not displaying properly ie, an extra ' / ' is appearing in the place of index,php
|
0

Try the below code to remove index.php from url, Make an htaccess file in the root folder and paste the below code in it.

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

For remove index.php in the url you need to change the configuration. Change the following in your config.php file

$config['index_page'] = "index.php";  

TO

$config['index_page'] = "";

This will remove index.php from url.

Comments

0

If it helps anyone here, this problem drove me crazy and the solution for me was removing the capital letters from the project folder (it was originally localhost/working/CourseIgnite/).

so after many attempts at the problem I changed site to localhost/working/courseignite/

Then using the solutions that everyone posts worked. Mod rewrite on, change base url and index in the config, and used the below in the htaccess.

Just hope this helps as it was driving me bonkers.

RewriteEngine on
RewriteBase /working/courseignite   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Then in application/config

$config['index_page'] = "index.php";  

TO

$config['index_page'] = "";

and also in application/config

$config['base_url'] = "yourlocalhostip/working/courseignite/";  

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.