views:

497

answers:

2

I'm making a downloadable self-hosted web app (using CodeIgniter), and need the .htaccess rewrite rule to be able to tell if it's in a subdirectory or not to be able to make the rewrite rule correctly.

For example, if the app is being installed at example.com, then the write rule will look like

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

If, on the other hand, it's installed at example.com/subdir, then it'll look like

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

How can I make this happen? Is there a way to combine those into one "smart" rule? Or do I need to create the .htaccess programmatically during the app's installation rather than just bundle it with the download?

A: 

try this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /index.php/$1 [L]
FDisk
+4  A: 

Simply use a relative path in your substitution:

RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
Gumbo
What does that first line do exactly?
Mike Crittenden
@mcrittenden: The additional condition is to exclude `index.php/` from being rewritten to avoid an infinite recursion.
Gumbo