1

例如:

- index.php
- /system
- /application
   - /controller
      - test.php (class:test ; function index() ; echo "hi")
- /public
   - style.css

我将浏览器指向http://mysite.com/它会显示“hi”

如果我想要style.css,我必须指向http://mysite.com/public/style.css

但我想指出http://mysite.com/style.css也可以显示 style.css

我尝试在系统和应用程序之前将 index.php 移动到公共添加前缀 ../

我还在根目录中设置了一个 htaccess,然后我可以成功地将http://mysite.com/style.css指向style.css

但是还有另一个问题,我不能再指向我的测试控制器了,它显示错误 404

我怎样才能保留两个网址?

更新:

根目录中的 htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^public/.+$ - [L]

RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+$ /public/$0 [L]

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

当我访问http://mysite.com/style.css可以显示 style.css

但控制器测试不起作用,我访问http://mysite.com/test/test/index显示 404 不是“嗨”

4

1 回答 1

1

您可以使用 a 测试RewriteCond请求的文件是否来自公共目录

# prevent requests for the public directory from being rewritten
RewriteRule ^public/.+$ - [L]

RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+$ /public/$0 [L]

您必须在 Codeigniter 规则之前插入此规则,否则文件可能会被重写为/index.php/....

更新

首先,您必须省略RewriteCond !-f/!-d.

的 URLtest/index必须是http://mysite.com/test/indexhttp://mysite.com/test

于 2013-04-05T19:11:56.210 回答