I can't remove the index.php from the CodeIgniter URL - php

I want to remove index.php from the path in CodeIgniter.
I tried to change the value of index_page in the config file as the following:
$config['index_page'] = '';
then I tried all these .htaccess :
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]
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index\.php|assets/|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
But none of them has worked.
I also tried to to change the uri_protocol to this :
$config['uri_protocol'] = 'ORIG_PATH_INFO';
But it's still doesn't work.
How can I solve this problem ?
Edit :
I tried this code to check if the mod_rewrite is enabled :
<?php
if( ! function_exists('apache_get_modules') ){ phpinfo(); die; }
$result = ' not available';
if(in_array('mod_rewrite',apache_get_modules())) $result = 'available';
?>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p>
And I get this result :
Apache/2.2.22 (Ubuntu)
mod_rewrite not available

I had the same issue.. then finally it worked with the following code
just follow these simple steps :
1. save the following code into .htaccss file..
2. put it in the main project folder (not the application folder)
3. rename the "/projectFolderName/" part on 3rd line of the code as
your project folder name.
Then you are done. Refresh and see.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projectFolderName/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

This works for me. Inyour .htaccess file write:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and in your config.php file :
$config['uri_protocol'] = 'AUTO';
Make sure yout htaccess is in your root folder not in applications folder.

Related

Codeigniter remove index.php from URL localhost:82/project

I have URL
http://localhost:82/project/index.php/home
I want to remove index.php from above url.
Like this : http://localhost:82/project/home
I have used many solution
1) I have remove index.php from config.php file :
$config['index_page'] = '';
2) change "uri_protocol" in config.php file :
$config['uri_protocol'] = 'REQUEST_URI';
My htaccess :
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Anybody master here to solve my question ? Thanks in advance.
use this Codeigniter .htaccess file and install it to your root app.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Like this one...
project_name
-application
-assets
-system
-user_guide
-.htaccess // like this one
Try To Use This
RewriteEngine on
#RewriteBase /project/
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
I use it and work on me.
Thank You
Set your base URL in config as
$config['base_url'] = 'http://localhost:82/project/'
In your .htaccess, Try with this, I have used this in my CI projects.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Place this file in your project folder.
If you are using Apache Server, you must do mod_rewrite enabled. And then modify your .htaccess file with the code below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
For more information, visit here
Try similar question here

Codeigniter can't remove index.php

i really need help,
same as the title, my problem is can't remove index.php in my codeigniter
i had try many .htaccess code like :
// first
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projectFolderName/ --> i already change to my project name
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
//second
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
//third
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^(.*)$ index.php/$1 [NC,L]
//fouth
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
i had change my config like
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
in some reference
in my httd.conf
<Directory />
AllowOverride All
Require all denied
</Directory>
i move the .htaccess to main project folder (not in application)
but all doesn't work
You forget to set base_url in application/config/config.php.Set your base_url.
$config['base_url'] = 'your_url';
In root folder .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And also
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Working fine here..
That funny,
my url: http://localhost/Igniter
in my config:
$config['base_url'] = 'http://localhost/igniter';
you can be the same me, check url with link "igniter" replace "Igniter'

CI url formating not working

i am currently working with CI. I need some help with removing index.php from url.
I tried a lot and could not figure out my issue. I checked solution but was not helpful.
My .htaccess file ->
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]
also changed
$config['index_page'] = 'index.php';
to:
$config['index_page'] = '';
and made $config['base_url'] = 'my working url';
can anyone help ???
Can you try with this .htaccess :
Options -Indexes
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Codeigniter can't remove index from url

I am Using CentOS,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|resources)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteBase /var/www/html/site/
</IfModule>
but geting same problem my pages with index.php works fine but when i remove index.php
it's not working...
I think it will help you as i am using this one.Put this code in your root folder's htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Please let me know if it is working or not.
This can be a few things.
1( remove the index page from your config file (application/config/config.php)
$config['index_page'] = '';
2( Do you have base_url like this:
$config['base_url'] = 'http://yourdomain.com/';
Note the / at the end.
3( try this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Simple at your config.php file at your config folder search for index url (index_page) and make it empty
$config['index_page'] = '';
Try this it works for me ccnd is my files folder.
RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|images|css|js|lib|img|bootstrap|robots\.txt)
RewriteRule ^(.*)$ /ccnd/index.php/$1 [L]
RewriteEngine On
RewriteBase /site_root/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Important:
1. you must set $config['index_page'] = ''; in config.php file.
2. site_root is folder name like, wamp/www/site_root.

cannot remove index.php in CodeIgniter application

I'm deploying the web application that we made in our live server but then im having troubles in figuring out how to remove index.php.
i have read several blogs regarding how to remove index.php in codeigniter application.
i have tried this settings on my .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and on my config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
but i still can't figure out how to remove it. Do i need to edit something in the apache httpd.conf?
thanks!
Can you try removing the ? that is present after index.php in your .htaccess:
Change:
RewriteRule ^(.*)$ index.php?/$1 [L]
To:
RewriteRule ^(.*)$ /index.php/$1 [L]
This is the one I use. Tried 3 different ones before I found one that worked
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon \.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

Categories