开发者

Using .htaccess mod_rewrite to bypass a deep directory structure to CSS assets

开发者 https://www.devze.com 2023-01-25 05:26 出处:网络
I have a setup like so http://localhost/ http://localhost/ci_tada/ http://localhost/ci_tada/application http://localhost/ci_tada/application/views

I have a setup like so

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.cs开发者_StackOverflow社区s

I dont want to have to write

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

every time i wish to access a css file (the same will apply for images ect)

I want to be able to just use http://localhost/ci_tada/css/master.css

and have it load the correct file.

The .htaccess file is located in the ci_tada folder.


Looks like you're using some sort of routes within a framework. You should check, because some frameworks give you the option to do it in the app configuration.

<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 inline in your views. Also see these resources if they can help:

  • http://codeigniter.com/forums/viewthread/60563/#297784


I feel you are talking about Zend Framework. Your few lines are

/

/application

How can every request can be redirected to CSS/? Then your application will not work!

In Zend Framework, application/layouts/scripts/layout.phtml, you mention css file like this:

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

Css file go in project folder. It is outside application folder: \quickstart2\public\css.

Hope I will not receive -ve answer.

0

精彩评论

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