remove codeigniter index.php

in Code one response

In the process of developing with codeigniter I discovered that the .htaccess file wasn’t removing the index.php file from the URL, this is because I was using a sub directory. I did however find code that made this problem go away. Take a look:

#this is for sub directory - http://localhost/appname
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

This then fixed the problem. But then when moving it over to a subdomain I ran into the same problem. So, I found some other code to help me fix the problem. Take a look:

In the .htaccess file of your root put this (change ‘myapp.mydomain.com to your full URL and change ‘myapp’ to your subdomain name):

RewriteCond %{HTTP_HOST}    ^myapp.mydomain.com$
RewriteCond %{REQUEST_URI}  !^/myapp/
RewriteRule (.*)            /myapp/$1 [last]

This will direct your request to the .htacess file in your subdomain. You then need to put the following code in the .htacess file of your subdomain:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1[QSA]

Problem solved.

 

1 Trackbacks/Pingbacks

 

Have something to say?