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]
Related
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.
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.
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
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.
I tried everything on google related to removing index.php from URL in codeigniter but no solution worked for me
I am using codeigniter version 2.1.0
How I can remove index form my URL ?
Thanks
In application/config.php make sure that
$config['index_page'] = "";
Then set this as your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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 %{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
</IfModule>
You're all set!
For me, Raphael Caixetas solution didn't work, but this did :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
i tested this on apache2 on many different hosting and it works great.
use this htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
be sure you have enabled mod_rewirte with a phpinfo();
then do this in config/config.php:
$config['index_page'] = '';
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
if it doesn't works yet, try to change the $config['uri_protocol']='AUTO' to one of the listed inside application/config/config.php file on line 40/54:
sometimes i used : REQUEST_URI instead of AUTO or "QUERY_STRING" for goDaddy hostings
Have you tried using the example given in the CodeIgniter user guide?
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
You can easily remove this file by using a .htaccess file with some
simple rules. Here is an example of such a file, using the "negative"
method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php,
images, and robots.txt is treated as a request for your index.php
file.
http://codeigniter.com/user_guide/general/urls.html
check your httpd.conf file
change
AllowOverride None
to
AllowOverride All
This is what I use and works.
Use this code in your .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php/$0 [PT,L]
Just make sure the .htaccess is in your root folder. (ie: xampp/htdocs)
Then in your config.php(application\config) replace
config['index_page']='index.php'
to
config['index_page']=''.
In addition of the .htaccess file given by Robert Stanley (see his answer), go to application/config/config.php, look for $config['index_page'] = "index.php"; and replace it with $config['index_page'] = "";
Don't forget to change de config file!
application/config.php
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
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 ...