0

I used the code below to remove index.php in codeigniter in my .htaccess file. But the thing that I am confused is where should i use the file. should i use it inside my www folder outside the application or inside the application.

I used it in all places, and it worked but it is messing up with my css or say base folders. How can I overcome the problem. Should i use the html base tag?

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

EDIT

my folder structure is

basefolder
  -application
  -css
  -js
  -images   
  -system
.htaccess
index.php
4
  • it goes in the CI installation directory. In your case it may be www. You can exclude media folders in the rewrite rules Commented Feb 5, 2013 at 0:39
  • can u give me the idea how to exclude them? Commented Feb 5, 2013 at 0:42
  • farinspace.com/codeigniter-htaccess-file here is a codeigniter .htaccess you can use . . Commented Feb 5, 2013 at 0:46
  • i updated. simply add the directories delimited by a pipe to the condition. Commented Feb 5, 2013 at 0:56

5 Answers 5

2

You can add an RewriteCondition which excludes all exisiting files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Sign up to request clarification or add additional context in comments.

Comments

1

use this

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

if doesn't works check if you enabled mod_rewirte in phpinfo();

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:

|
| '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';

sometimes i used : REQUEST_URI instead of AUTO

Comments

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

This assumes css is in the same directory as index.php, etc. This rule depends on your file structure. If you update your question with an example of your directory tree I can modify the rules.

There should be no other configuration needed for this since you mention it works but just messes things up.

It should be noted, this one pasted is the only thing in my CI htaccess file and mine works fine.

Also, see Will's comment. My config url suffix is always ""

1 Comment

as far as codeigniter goes however, you also have to update the config file and set $config['url_suffix'] to ""
0

My solution, CI system move up (not public from the web), applications are public, .htaccess for each subdomains (in root directory), but its depends on your structure (many solutions exists)

RewriteBase /
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] 

Comments

0

copy and paste below code in .htaccess file

Options +FollowSymLinks

RewriteEngine On

Options -Indexes

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP/ RewriteRule ^index.php$ http://www.yoursite.com/ [R=301,L]

Comments

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.