开发者

Making a .htaccess rewrite rule respect subdirectories automatically

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 r开发者_Python百科ather than just bundle it with the download?


Simply use a relative path in your substitution:

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


try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜