views:

232

answers:

2

I'm made a codeigniter app and I tried to use the apache mod_rewrite rules as

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

The problem is that I have this app in a folder abc/ but when I type mysite/abc/something (which should point to mysite/abc/index.php/something) I get redirected to mysite/index.php/something

What changes should I make to the .htaccess file to make it work properly?

+1  A: 

Try using a relative path in the substitution:

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Gumbo
+2  A: 
RewriteCond $1 !(index\.php|^images|^robots\.txt)
RewriteRule (.*) index.php/$1 [L,NS]
chaos
did you forget the `^` or is it like that? moreover what does [L,NS] do?
apnerve
I removed the initial ^ on the RewriteCond so that it will ignore any index.php in your site, not just /index.php (^index.php will NOT match /abc/index.php; it being in a .htaccess in a subdirectory does not make the paths relative to that subdirectory). The ^ and $ in the rule were irrelevant.
chaos
The NS suppresses the rule on subrequests. When the rule triggers, a subrequest is generated with index.php/whatever as the URL; the NS stops the rule from looking at the subrequest. The RewriteCond's index.php check should also prevent that from being rewritten, so it's kinda belt-and-suspenders.
chaos