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 a codeigniter site http://piyukarts.in/mss/ where in .htaccess file under mss contains
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
but i cant access a link http://piyukarts.in/mss/posts, but i can access piyukarts.in/mss/index.php/posts, with this index.php/ after mss/
piyukarts.in/ is wordpress site, also having a .htaccess file
Please help.. thanks a ton in advance...
I made this change in .htaccess file and its working fine now.
RewriteEngine On
RewriteBase /mss
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ /mss/index.php?/$1 [L]
To answer:
can another .htaccess file can work in subfolder
is:
Yes.
.htaccess files in any folder in the file path tree to the file, will be applied to the file.
so file as /root/home/site/includes/css/horses.css the htaccess in any of those folders would be applied to the file horses.css .
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>
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 have a url which initially http://web.com/index.php/home/funct/ and I want to change this by removing the index.php so that it becomes http://web.com/home/funct/
If you are using Apache server, create a file called .htaccess and put this in it:
<IfModule mod_rewrite.c>
RewriteEngine on
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
Then just remove the reference to "/index.php/" from your links and when the server doesn't find "home/funct" it will go looking for "/index.php/home/funct".