Codeigniter 3 Remove index.php Problems - php

I have a little project that i developed for a client in codeigniter 2.1.4 and now, he insists to migrate to codeigniter 3 DEV version. I know that's not a good ideea but...
My problem is that i can't remove the index.php from the url.
This is my .htaccess file :
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I have removed the index.php from the config.php file
No luck
I reinstalled the LAMP server (i'm on Ubuntu 12.04'), reconfigured I have other projects on my local server developed on Codeigniter 2.1.4 and Laravel 4 and they work just fine but this one it's killing me.
Thank you!

I made this way:
Created the .htaccess in the root folder of the project with the content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
Then, in the config.php i modified this line.
From:
$config['url_suffix'] = 'index.php';
To:
$config['url_suffix'] = '';

Kindly add the below codes to .htaccess file and include it directly to your /codeigniter_project_folder/.htacess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Remove the ? after index.php

Add following lines in .htaccess file
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
And also Edit application/config/config.php file. with
$config[‘index_page’] = “”;
$config[‘uri_protocol’] = “AUTO“;
It will Work.

Make a .htacess file in your project root folder /Your_codeigniter_project_folder/.htacess and paste this code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
set a base URL in config.php file $config['base_url'] = 'http://yourhost/CI_project_folder/';
set URL suffix $config['url_suffix'] = '.php';
* If not work please check this *
Make sure in your root folder where .htacess stay there have not any file which name is same like your controller name.
Example: you have a users.php controller also you have a file in /Your_codeigniter_project_folder/users.php
If have please remove it /Your_codeigniter_project_folder/users.php
Make sure your server is rewrite mode on( remove # from start of this line)
LoadModule rewrite_module modules/mod_rewrite.so

create new .htaccess file on root of your CI project and add your code there. Do not change .htaccess file on application folder. That's work for me

Just Download CI version 2.2.0
Copy .htaccess and htaccess.txt from root and paste it in your Codeigniter 3 project.
Don't forget to change project name from .htaccess file.

Create an a new htaccess file in your www/project_folder or your htdocs/project_folder
Make sure mod_rewrite is working my using echo phpinfo()
Simply paste the following code and it should work:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project_folder/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Change the project folder to that of your own

Be careful about the project path uppercase.
i.e. if the base_url is http://localhost/ci/ and the directory name is CI, it may not work.

I have clone the git repository again and made a clean install of the lamp and now it works.

Related

Why is this .htaccess file mod_rewrite not working?

I'm using MAMP and CodeIgniter.
The root of my website is: /Users/Roy/Websites/CodeIgniter-3.0.2
In the Websites folder I also have some other project but I don't think that matters. Here is the apache httpd.conf file: http://pastebin.com/Am0ew0C0
In my .htaccess file I'm using the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
the .htaccess file is located at: /Users/Roy/Websites/CodeIgniter-3.0.2/.htaccess
I have no idea why the mod_rewrite isn't working, it's supposed to eliminate the use of index.php in the url because the URL I have to use now is: http://localhost:8888/CodeIgniter-3.0.2/index.php/about
And I would like that to become: http://localhost:8888/CodeIgniter-3.0.2/about PHP version 5.6.10 is used. the .htaccess file is not being read by apache, that is the problem here, how to fix it?
Problem solved, there is no need to mess with the httpd.conf with MAMP installed. Simply get CodeIgniter and place it in the htdocs folder inside MAMP. After that create a .htaccess file inside the CodeIgniter folder (not the application folder inside there) and use the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Now you have clean URL's and no longer need to use /index.php/about but can just do /about.
It maybe from the fact of what you set your document root to /Users/Roy/Websites/ in your httpd.conf file. Personally I would use virtualhosts if you plan to have multiple websites so that each one can have it's own .conf and you can set the Document root specifically for each site.
Anyway, so right now your CodeIgniter-3.0.2 is a subfolder of Websites which is your document root. So most likely you're having a problem with the rewrite base.
If you have your files and .htaccess in the codeigniter folder, your .htaccess will need to look like this.
RewriteEngine On
RewriteBase /CodeIgniter-3.0.2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
You can use this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Project_Name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It look like file permission issue. check out the properties of your .htaccess file and change the permission.
The try with this code.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
for more try http://w3code.in/2015/09/how-to-remove-index-php-file-from-codeigniter-url
.htaccess could be very frustrating. take a lot at what really works
1.Your .htaccess should look like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /booking/
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>
2.Replace line 3 with the root directory name of your project, in my own case 'localhost/booking/'
3.Copy the .htaccess file from the application folder to the root directory. This means that you will now have to instances of .htaccess file in you entire project.
4.in your config.php , Base url should look like this in my own case
$config['base_url'] = 'http://localhost/booking/'
5.
$config['index_page'] = '';
6.
$config['uri_protocol'] = 'REQUEST_URI';
7. turn on Mod-rewrite in your httpd.conf file by removing the # preceding this line
LoadModule rewrite_module modules/mod_rewrite.so
I hope this solves your problem

Remove index.php in Codeigniter URL

How to remove index.php in Codeigniter url?
http://localhost/Sample/index.php
to just
http://localhost/Sample
I've been searching whole day in the internet and nothing works. I'm using Apache2.2 and the mod_rewrite in httpd.conf have already been enabled. The version i'm using is Codeigniter 2.1.4.
Please teach my step by step. I'm still very new in Codeigniter Framework. Thanks !
You can use the below code in your .htaccess file :
RewriteEngine On
RewriteBase /my_project_name/
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
There are two places that you must make this change, one is in your /application/config/config.php:
/*
|--------------------------------------------------------------------------
| 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'] = '';
Remove the index.php from index page.
The 2nd place is (as mentioned) in updating/creating your .htaccess file, that sits in the same root folder as your primary index.php file.
Referer to the CI guide: http://ellislab.com/codeigniter/user-guide/general/urls.html
It's all in the guide...
Try this on your .htaccess file found in the root folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
You just need to create .htaccess file in project folder and write:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
#And You don't need to define in base_url in config file:
$config['base_url'] = '';// blank it.
I hope it will work perfectly ...
First Enable "mod_rewrite" in Apache server.
Restart your Apache server.
Add this code to .htaccess (Folder structure is Project_Name/.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

CodeIgniter remove index.php from url

I'm having some trouble removing index.php from my CI app urls. Followed the official documentation here but apparently something's missing yet.
I setup a CI app and placed it on /var/www/test on my server, where test is a symlink pointing to /home/user/websites/test.
Everything is working fine if I do http://myIp/test/index.php/welcome, but working if I do http://myIp/test/welcome.
I included an .htaccess in my test folder, containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and also played with RewriteBase property without success.
What am I doing wrong or missing?
put the following in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
put this file near to index.php out of application and system folders and near to them
don't forget to write $config['index_page'] = ''; instead of $config['index_page'] = 'index.php';
Open application/config/config.php, and change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Try this one :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Your rewrite rule is incorrect (or faulty at best). It should be as follows
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The [L] flag in the RewriteRule indicates to apache that no further rules should be processed and that the rule should be applied immediately. See the apache documentation about the L flag for more information on this. In your case this is important due to the fact that you are using symlinks and .htaccess file instead of applying the rule to your vhost file directly, which is highly recommended given this case as well as the case that .htaccess is slow.
If i have got your question right you want to make your links working & remove 'index.php' from URL.Follow following steps & let me know if that solves your issue.
1) Remove 'index.php' from config.php which is located in config directory make it look like this $config['index_page'] = '';
2) Add this to .htaccess file
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
If you have any doubts or issues let me know.Hope it helps.
Best Regards, Zeeshan.

Want to remove Index.php from Codigniter URL

I want to remove index.php from code igniter URL ,I had created .htaccess file and stored it in application folder parallel to index.php and also remove
$config['index_page'] = '';
from config.php.
Code in .htaccess file, which is not working :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
URL of the project is:
localhost/WCPM/index.php
NOTE:Please Don't mark this question as duplicate because I had already tried lots of solution for the same but none of them works for me , so at last I am asking this question here for the solution
In Config.php Change as Follows
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/WCPM/';
And Create .htaccess file like
RewriteEngine on
RewriteCond $1 !^(index\.php|[WCPM])
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
and Save this in Root Folder [WCPM] i.e. near Application Folder.
For More Details Refer the CI Manual # http://ellislab.com/codeigniter/user-guide/general/urls.html
Enable mod_rewrite module in apache.
If that doesnt work or mod_rewrite is already enabled, try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
First of all, change following setting in your config file.
$config['index_page'] = '';
and then, replace .htaccess file located at your project root folder not in the application folder with the following code..
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
There is a full article for this at:
http://www.web-and-development.com/codeigniter-remove-index-php-minimize-url/#remove-index-php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^media/imatges/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1 [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>
This is the entire recommended code to put at the start of your .htaccess file

Remove index.php from codeigniter url

I am a newbie at codeigniter. I have my codeigniter installed at localhost/path/learn_ci.
I have followed all the steps given in the codeigniter wiki. Here is my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /learn_ci/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I've also changed the config file as required. But when I try to access
I get this error
"The requested URL /learn_ci/index.php/welcome was not found on this server"
I have double checked...the mod_rewrite module in Apache is on.
The RewriteBase solution also didn't work. Am I doing something wrong??
As others have said, make sure that AllowOverride is set to All in your apache config or your virtual host file.
Given the path that you have codeigniter setup in, your htaccess should look like this:
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/index.php/$1 [L]
Also, remember that any assets you are using (img, css, js, etc) are referenced either with the base_url() function or using relative paths. The root of your project is going to be /path/learn_ci.
I find that it is easier to create a virtual host and add an entry to my hosts file locally. This mimics real life much better.
Try:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
You can do the following:
First in config.php file set
$config['index_page'] = '';
Next, create a .htaccess file in the codeigniter root folder and add the following content:
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
Save the file. It should work.
You place the htaccess file in your root public_html folder in the same directory as index.php
Then remove /learn_ci from your htaccess file, just make it /index.php/$1
Check your apache config, it should be something like :
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
I thought to add my answere. My project base url is http://localhost/newproject/
I included htacess file in the newproject folder.
here is the code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
then I change config file.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
and every thing started to work. now nomore index.php file.

Categories