2010-11-17 33 views
0

我有像这样的.htaccess mod_rewrite的绕过了深刻的目录结构CSS资产

http://localhost/
http://localhost/ci_tada/
http://localhost/ci_tada/application
http://localhost/ci_tada/application/views
http://localhost/ci_tada/application/views/css
http://localhost/ci_tada/application/views/css/master.css

的设置0

我不希望有每次我想访问一个CSS文件时,写入

http://localhost/ci_tada/application/views/css/

(同样适用于图像ECT)

我希望能够到只需使用 http://localhost/ci_tada/css/master.css

并让它加载正确的文件。

.htaccess文件位于ci_tada文件夹中。

回答

0

看起来你在框架内使用某种路线。你应该检查一下,因为一些框架可以让你选择在应用程序配置中执行它。

<IfModule mod_rewrite.c> 
RewriteEngine On 

# directory base, untogle if you want to 
# rewrite only starting from /<directory/path> 
# RewriteBase/

RewriteRule ^/css/(.*)$ index.php/ci_tada/application/views/css/$1 [PT,L] 
#or RewriteRule ^/(.*)/css(.*)$ index.php/$0/views/css$1 [PT,L] 
#or RewriteRule ^/(.*)/css/(.*)$ index.php/$0/views/css/$1 [PT,L] 

</IfModule> 

Beware that the last two redirect everything that contains /css/ in the path.


edit:1: It is considered best practice in CI (from what I've read), to set a static directory on your root like this:

 

    /
    .../static 
    ......./css 
    ......./js 
    .../application 
    ......./controller 
    .../... 

So that you can simply use /static/css/file.css内嵌于您的意见。还看到这些资源,如果他们能帮助:

+0

啊,我什至没有想到路由。关于如何在代码Igniter中执行路由的任何想法,据我所知,路由仍然通过index.php – Hailwood 2010-11-17 02:32:14

+0

回复上面编辑:1 – eagleal 2010-11-17 02:38:33

+0

您可以告诉我们您的.htaccess,所以我可以集成它与上面的答案。也看到这个SO线程,如果它有帮助http://stackoverflow.com/questions/3729340/how-do-i-add-some-static-routes-to-a-codeigniter-app – eagleal 2010-11-17 02:59:17

0

我觉得你说的是Zend框架。你的几行是

/

/应用

怎么能每次请求可以被重定向到CSS /?那么你的应用程序将无法工作!

在Zend Framework中,应用/布局/脚本/ layout.phtml,你提到的css文件是这样的:

<?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/site.css'); ?> 

CSS文件进去项目文件夹。它在应用程序文件夹外部: \ quickstart2 \ public \ css。

希望我不会收到答案。

+0

Code Igniter实际上:) – Hailwood 2010-11-17 02:27:34

+0

好吧,ZF有这个设施。代码点火器也应该有这样的。如果您在开发时修复代码,那么在后期阶段,您可能会遇到麻烦! – 2010-11-17 02:45:09