EllisLab text mark
Advanced Search
1 of 3
1
   
How remove index.php from URLs? [SOLVED]
Posted: 21 May 2010 02:50 PM
Joined: 2010-05-05
39 posts

I’m following exactly what’s in the User Guide, but still cannot remove index.php from my URLs.

- My “system” folder is at my root
- My controller called “home” is located at /system/application/controllers/home.php

- This works: http://localhost/index.php/home
- This does not work: http://localhost/home

Here what I added to my .htaccess file:

RewriteEngine on
RewriteCond 
$!^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L] 


It looks like the index.php file at the root needs to be executed before the path to the controllers can be discovered?

Thanks.

 
Posted: 21 May 2010 06:56 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2006-01-27
16 posts

try this:

RewriteEngine on
RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
.* index.php/$0 [PT,L] 
 
Posted: 04 June 2010 01:52 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-05-05
39 posts

Thanks, this works for me!

I also had to add the .htaccess file to my root directory.
A little tricky since Macs hide all files that start with with a “.”.
But I used a utility called InVisibles to toggle between seeing/hiding invisible files.

 
Posted: 19 July 2010 03:26 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-18
13 posts

My thanks as well, rufnex.  That worked perfectly for me.

 
Posted: 20 July 2010 01:11 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-06-30
24 posts

Where do we put the .htaccess file?

If my url is like :
localhost/devapp/index.php/<<controllername>>/<<function name>>/

I want this to be
localhost/devapp/<<controllername>>/<<function name>>/

I have written the .htaccess file as :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Where do I put this .htaccess file?

I tried out many combinations but, I kept getting a 500:Internal Server Error.

 
Posted: 20 July 2010 01:16 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-05-05
39 posts

I have it in my document root.

I have a MAMP stack installed on my Mac, and my document root is:  /Applications/MAMP/htdocs

 
Posted: 20 July 2010 01:26 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-06-30
24 posts

I have WAMP.

So must it be in the application folder of my application?

 
Posted: 20 July 2010 09:22 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-18
13 posts
vindhyareddy - 20 July 2010 05:11 PM

Where do we put the .htaccess file?

If my url is like :
localhost/devapp/index.php/<<controllername>>/<<function name>>/

I want this to be
localhost/devapp/<<controllername>>/<<function name>>/

(...)

Where do I put this .htaccess file?

I tried out many combinations but, I kept getting a 500:Internal Server Error.

I believe that the file should be in the folder that has your CodeIgniter installation, in your example in your devapp folder.  (It should be in the same folder as the index.php file.)  I haven’t tried it on my localhost, but that worked fine on my online server.

 
Posted: 20 July 2010 11:51 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

Dunrobin is correct. I run WAMP locally as well. htaccess should go into same folder as your CI’s index.php file.

 
Posted: 21 July 2010 12:00 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2010-06-30
24 posts

http://ellislab.com/forums/viewthread/161533/

This is the place where another problem discussion is going on!
Can you’ll help me out there?

 
Posted: 22 July 2010 12:50 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2010-02-28
47 posts
pickupman - 21 July 2010 03:51 AM

Dunrobin is correct. I run WAMP locally as well. htaccess should go into same folder as your CI’s index.php file.

Say the index.php file in is a folder named DCS. Using WAMP the DCS folder would be within the www folder. So does this mean the .htaccess file will need to be in the DCS folder and not the www folder?

‘Cause I am having a problem where index.php has been removed, I am able to see the main page, but when I click on a link, it says the page cannot be found. Could me having the .htaccess file in the www folder instead of DCS cause this problem?

 
Posted: 22 July 2010 12:59 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

You want the .htaccess to be in your CI installation folder. So, if you have it in DCS, that’s where it should be.

 
Posted: 28 July 2011 01:34 PM   [ # 12 ]   [ Rating: 0 ]
Joined: 2010-08-13
36 posts
rufnex - 21 May 2010 10:56 PM

try this:

RewriteEngine on
RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
.* index.php/$0 [PT,L] 


This works for me whereas the code on the Wiki does not. Could someone perhaps explain how this works?

Thanks

 
Posted: 21 August 2011 03:42 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2010-12-29
2 posts

One very important change one has to do to the apache configuration file (httpd.conf) to make the URL Rewriting to work is to ensure that the “Options FollowSymLinks” is done for the directory in which CI is installed. Please see the following example (I am running apache on my Mac Snow Leopard and the apache configuration file is at /etc/apache2/httpd.conf)

My CI Installation is in the directory starwood2012

Here is my Directory directive in the httpd.conf (I added this to make the url rewriting work)

<Directory “/Users/Ashok/Sites/starwood2012”>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Further information:

This is the URL that now works:

http://localhost/~Ashok/starwood2012/landing

The equivalent real URL of the above rewritten URL is

http://localhost/~Ashok/starwood2012/index.php/landing

Here is my .htaccess file contents and my .htaccess file is in the directory starwood2012 (The CI Installation directory).

RewriteEngine on
RewriteBase /~Ashok/starwood2012
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

RewriteBase should be everything between your domain name and the controller with NO trailing /

Also ensure that you have $config[‘index_page’] = ‘’; in the application/config/config.php file. You should also have the mod_rewrite enabled (uncomment this line if it is commented in the httpd.conf file - on Mac this enabled by default)

Hope this helps a lot of CodeIgniter users (especially those who work on a Mac)

 
Posted: 18 December 2011 07:07 AM   [ # 14 ]   [ Rating: 0 ]
Joined: 2011-10-14
3 posts
rufnex - 21 May 2010 06:56 PM

try this:

RewriteEngine on
RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
.* index.php/$0 [PT,L] 

it is not working for me bro. I just copy and paste in my application/.htaccess file, plz give any suggestion

 Signature 

Coding like a boss g:-)

 
Posted: 18 December 2011 12:25 PM   [ # 15 ]   [ Rating: 0 ]
Joined: 2010-12-29
2 posts

1. Please ensure “Options FollowSymLinks” is done for the directory in which CI is installed. This is done in the httpd.conf file. In your httpd.conf file you need to add the following lines. Make sure that you change the Directory to the one relevant to you (/Users/Ashok/Sites/starwood2012 - This should be changed in the following code block to your CI installation directory).

<Directory “/Users/Ashok/Sites/starwood2012”>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

2. The .htaccess file should be in the CI installation directory. To me you sounded like you have it in your application directory.

3. In the contents of the .htaccess file you provided - I see you do not have the RewriteBase line. Please add this line.

RewriteBase should be everything between your domain name and the controller with NO trailing /

Please refer once again to my original post and ensure the you have the RewriteBase with the correct path in it.

Thanks.

 
1 of 3
1