How do I remove the "index.php" sticking out in every path in codeigniter somewhere in the center?
I want clean non index.php-fied URLs?
If you are using Apache place a .htaccess file in your root web directory containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
I had some big issues with removing the index.php. As a general rule the .htaccess below has been tested on several servers and generally works:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
If you don't have any luck with that then the next step is to adjust your config file. Try some of the other URI protocols e.g.
| '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'] = 'ORIG_PATH_INFO';
If your still not having any luck try changing the rewrite rule to include your subfolder. This is often a problem if your using a temporary URL on a dev server etc:
RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]
Just play around with these options, one should work. Also, make sure your index file is set to:
$config['index_page'] = '';
Good luck!
Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)
And Add the following rules to .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then find the following line in your application/config/config.php file
$config['index_page'] = 'index.php';
Set the variable empty as below.
$config['index_page'] = '';
That's it, it worked for me.
If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one
$config['uri_protocol'] = 'AUTO';
Have a look in the system\application\config\config.php file, there is a variable named index_page
It should look like this
$config['index_page'] = "index.php";
change it to
$config['index_page'] = "";
Then as mentioned you also need to add a rewrite rule to the .htaccess file
Note: in CodeIgniter v2 this file was moved out of the system folder to application\config\config.php
All above methods failed for me and then I found that I was not changing AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
...
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /codeigniter/index.php/$0 [PT,L]
after changing RewriteRule .* index.php/$0 [PT,L] with the project folder name "codeigniter".its working for me. Thanks guys for your support.
Step 1 => Place your .htaccess file in root folder where application and system folders exist.
Step 2 => If your web path using sub-folder like - yourdomain.com/project/ - then use following code in htaccess file
RewriteEngine on
RewriteBase /project/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]
If your web path using root-folder like - yourdomain.com - then use following code in htaccess file
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Just thought i might add
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
would be the .htaccess and be sure to edit your application/config.php variable in the following manner:
replace
$config['uri_protocol'] = “AUTO”
with
$config['uri_protocol'] = “REQUEST_URI”
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
This must definitely work.. have a try
Ensure you have enabled mod_rewrite (I hadn't).
To enable:
sudo a2enmod rewrite
Also, replace AllowOverride None by AllowOverride All
sudo gedit /etc/apache2/sites-available/default
Finaly...
sudo /etc/init.d/apache2 restart
My .htaccess is
RewriteEngine on
RewriteCond $1 !^(index\.php|[assets/css/js/img]|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Perfect solution [ tested on localhost as well as on real domain ]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
This is an .htaccess for one of my CI projects:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /projectFolder/index.php/$1 [L]
The last line should give you what you need, though you may or may not need '/projectFolder' depending on how your folder structure is set up. Good luck!
Use mod_rewrite as instructed in this tutorial from the CI wiki.
As an .htaccess file, a good option is to use the one provided by the Kohana Framework:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
It's a well thought out .htaccess that just works.
There are two way to solve index.php in url path for codeigniter
1:In config/config.php
Change code :
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
2:Create .htacess in root path if not created,Copy the following code:-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Save it and then check in your Apache Configuration rewrite_module OR mod_rewrite is Enabled.If not then please enabled.
(Best Approach)!
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_url'] = '';
|
| '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
Look in the \application\config\config.php file, there is a variable named index_page
It should look like this
$config['index_page'] = "index.php";
change it to
$config['index_page'] = "";
Then as mentioned you also need to add a rewrite rule to the .htaccess file like this:
RewriteEngine on
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
It work for me, hope you too.
If you are on linux and using apache2 server then we may need to override apache2.conf file also beside changes on .htaccess file. Find apache2 configuration file on /etc/apache2/apache2.conf .
Search Directory /var/www/ Change AllowOverride None -> AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory
place a .htaccess file in your root web directory
Whatsoever tweaking you do - if the above is not met - it will not work. Usually its in the System folder, it should be in the root. Cheers!
I have tried many solutions but the one i came up with is this:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots \.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
This iwill remove the index.php from the url as required.
I use these lines in .htaccess file; which I place in root folder
RewriteEngine on
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Then I can access http://example.com/controller/function/parameter
instead of http://example.com/index.php/controller/function/parameter
Step 1 :
Add this in htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Step 2 :
Remove index.php in codeigniter config
$config['base_url'] = '';
$config['index_page'] = '';
Step 3 :
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
for www folder
Step 4 :
Enabled apache mod rewrite (Command)
sudo a2enmod rewrite
Step 5 :
Restart Apache (Command)
sudo /etc/init.d/apache2 restart
This will help you
paste this code in application folder in .htacess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
<IfModule mod_php5.c>
php_value short_open_tag 1
</IfModule>
This one did me the complete magic:
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]
Hope it helps!
Hi This one worked me
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
as well as this
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
where the folder is the name of the subfolder if this codeigniter application is hosted as a subdomain
e.g domainname/folder/index.php.
Hope that works for you. Thanks.
Copy past following code in your .htaccess
RewriteEngine on
Options -Indexes
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Foldername of your ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Related
I am using codeigniter v3 for my website and I'm having problems redirecting from one page to another.
If I click the tab, the link shows localhost:8080/IDS/view/decisiontree and shows Object not found! The requested URL was not found on this server...
If I edit the URL and make it localhost:8080/IDS/index.php/view/decisiontree, the site perfectly loads.
Here are my routes:
$route['view/decisiontree'] = 'data_controller/goto_decisiontree';
Here are the codes of the tab related:
<li>Decision Tree</li>
Here is my data_controller:
public function goto_decisiontree(){
$data['page'] = "2";
$this->load->view('decisiontree_page', $data);
}
And here is my config.php:
$config['base_url'] = 'http://localhost:8080/IDS';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Here's my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And note, I'm using Codeigniter V3.
Thanks a lot for the help!
Try the following
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
In some cases the default setting for uri_protocol does not work properly. Just replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
HTACCESS
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Hope it helps .
Try this htaccess in main directory of your codeIgniter project. It seems to work fine in xampp and wamp.
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
config.php
$config['base_url'] = 'http://localhost:8080/IDS/';
$config['index_page'] = "";
$config['uri_protocol'] = 'REQUEST_URI';
All ways remember that you should have first letter of file name and class as upper case the rest lower case. refer
More htaccess examples here
Note: I'm on Ubuntu, so the paths here may change if you are on another distro.
I tried all .htaccess suggestions and none seemed to work, so I started thinking that was not the problem. And then it hit me, the apache.conf file. Doesn't matter the .htaccess you have, if that file is restricting the override, there's nothing you can do.
So i went to /etc/apache2/ and edited the apache2.conf file adding this:
<Directory /var/www/html/your-project-folder>
AllowOverride All
Require all granted
</Directory>
Also change $config['index_page'] = index; to $config['index_page'] = ''; in application/config/config.php as said above.
Btw, my .htaccess looks like this:
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And don't forget to restart apache.
Please try to set the index_page blank in config.php file
$config['index_page']= "";
Also please change the .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]
Try below in your .htaccess file
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
For more detail, you can visit here
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
I have seen other articles on the same issue. But none of the answers have solved my problem.
I am not using xampp or wamp but have setup php mysql apache seperately. Also I am using my own local domain for instance mytestsite.com.
My .htaccess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /TestCI/
# Canonicalize Codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(HomeController(/index)?|index(\.php|html?)?)/?$ / [R=301,L]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|TestCI) [NC]
RewriteRule ^(.*)$ http://www.mytestsite.com/$1 [R=301,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>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
I have also made following changes in config.php
$config['base_url'] = 'http://mytestsite.com/TestCI/';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO'; //AUTO
I have also made following changes in apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
But when i try to access
http://mytestsite.com/TestCI/HomeController/
its showing 404 error but works correctly when using
http://mytestsite.com/TestCI/index.php/HomeController/
I have looked into several similar questions that have been reported solved, but none of the answers have worked for me. Is there anything else that should be done to remove index.php from the url. Kindly respond back. Help highly appreciated.
It may be the htaccess isn't being used.
Put a sytax error in the file. (Append something like hdtbf to the file)
If that doesn't give a 500 error you need to turn allow override all
In your main Apache config
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Replace the following line of code in your .htaccess file
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Just put this code in your .htaccess :
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Thankyou for helping me... Problem is solved.
I made the following changes in my apache2.conf file
<Directory /Absolute path to .htaccess folder
AllowOverride All
Require all granted
</Directory>
Also I removed the RewriteBase parameter in .htaccess file which is where the actual pbm was.
My current .htaccess file looks like
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I have also made changes in config.php where i changed $config['base_url'] to codeigniter root path
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 ...