2013-04-05 59 views
1

在例如:笨公共目录中的URL

- 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到系统中的公开之前加前缀../ d应用

我也设置在根目录中的htaccess的,那么我就可以成功地指向http://mysite.com/style.css为style.css的

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

我怎样才能保持这两个网址是什么?

UPDATE:

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:

在根目录的htaccess没有“喜”

+0

这是有道理的有它在/公/并通过/public/style.css调用它;那有什么问题?另外,请发布您的.htaccess。 – stormdrain 2013-04-05 19:03:20

+0

这似乎是htaccess的在您重写规则有问题,发表您的htaccess更多的帮助 – bizzehdee 2013-04-05 19:04:36

回答

1

您可以用RewriteCond测试如果请求的文件是从公共目录

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

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

您必须插入笨规则之前此规则,否则该文件可能被改写为/index.php/...

更新

首先,你必须离开了RewriteCond !-f/!-d

test/index的URL必须为http://mysite.com/test/indexhttp://mysite.com/test

+0

这可以显示css文件,但我的控制器404 NT发现,我更新的问题 – 2013-04-05 19:20:24

+0

@jkjk显示在完成你的.htaccess题。 – 2013-04-05 19:22:08