0

I am trying to remove the index.php in the url for Code Igniter. According to the official guide, I should add the following code to the .htaccess file.

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

This is not working.

So I do more searches and some say that I should remove the default configuration on the index page, so I make the changes in the config.php file:

$config['index_page'] = '';

It is still not working. Then, on more searches, I found different version of the code, like this one (there is just an example, I have tried many version already)

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

I initially put the code in the .htaccess of the root directory, but as it is not working, I also try adding it to .htaccess in other directory. Yet, still not working.

I am just using the default welcome page for testing, so I am sure it is not the problem of coding. i.e.

http://localhost/projectFolder/CodeIgniter/welcome/

Anybody got idea what have I missed?

3 Answers 3

1

I'm assuming that whatever folder that http://localhost/projectFolder/CodeIgniter/ maps to is your docroot and that the .htaccess file is inside that directory.

If that is the case, then your code is correct - so it's a matter of your apache config. Make sure that you are allowing .htaccess files by changing the Directory block - AllowOverride All.

Take a look at this page for help doing that.

Sign up to request clarification or add additional context in comments.

2 Comments

This seems to be on the right path, but as I am using Mac and XAMPP, it seems that the link is not applicable to me. Do you have a version for Mac? (I am googling, but seems not much help out there)
Here's a link to the "what's where" on xampp for mac: apachefriends.org/en/xampp-macosx.html#876 -- You need to edit the /Applications/XAMPP/etc/httpd.conf file. If you're running vhosts, then you would edit a file named vhosts.conf (should be either in or around the same directory - maybe in a sites-available directory).
0

I think the following code should work for you

RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|public|themes|captcha|robots|documents|\.txt)
RewriteRule ^(.*)$ /projectFolder/index.php/$1 [L]

Hope this helps you.

Comments

0

Make this changes to config file

 $config['base_url'] = 'http://localhost/projectname/';
 $config['index_page'] = '';

Then in ur .htaccess try

 DirectoryIndex index.php
 RewriteEngine on
 RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 

Also make sure that you have mod_rewrite enabled in your apache configuration

The .htaccess file should be in root directory of your project, ie outside application folder

1 Comment

I am already using the configuration you posted and I have tried changing the script to the one you provided but it is still not working. I guess it is the mod_rewrite thing. How do I enable it? (I am using Mac with XAMPP.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.