cannot remove index.php in CodeIgniter application - php

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]

Related

The requested URL /link was not found on this server. Apache & htaccess

The root page at / loads fine, but any other link gives me a The request URL was not found on this server error.
my htaccess is in the root of the application folder, and contains the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
a CodeIgniter .htaccess might look alike this... the RewriteBase is important there.
<IfModule mod_rewrite.c>
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]
</IfModule>

Having a hard time rewriting codeigniter uri's

I am going through a few codeigniter tutorials online but I got stuck on rewriting uri's.
Here is my .htaccess code.
RewriteEngine On
RewriteBase jrdash
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]
I also made this change to the config file.
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
The .htaccess file is in the root project folder, and the project directory is jrdash within my xampp htdocs directory. I get a error when I try to load the page simply by typing in localhost/jrdash, I was getting the default Codeigniter screen before but then I made these changes and now I get an error.
I suggest you remove everything between the first and last-three lines and remove that question mark.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I didn't read your whole question because I'm pretty sure you've made the very classical mistake: your forgot to add the QSA directive!
RewriteEngine On
RewriteBase jrdash
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-D
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

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

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.

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.

Codeigniter without index.php changing in config and .htaccess not working

I have this issue with codeigniter for my subdomain where I would like to take out index.php but is not working for some reason.
I have set .htaccess with below:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|user_guide|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
and also config.php index_page settings have been changed like below:
$config['index_page'] = '';
do you know why it's not working?
And this is mine
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]
This is how mine is currently setup, hope this helps.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Categories