HOWTO:重写图片,CSS和每个应用程序的请求JS把不同的文件夹? [英] HOWTO: rewrite requests for images, css and js to different folders for each application?

查看:128
本文介绍了HOWTO:重写图片,CSS和每个应用程序的请求JS把不同的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个多应用codeIgniter网站,在这里所有的应用程序的资产将被存储在一个名为资产。这里面一个文件夹一个文件夹,每个应用程序将有它自己的资产的文件夹。所以,如果这是我的根目录...

I am trying to build a multi-app CodeIgniter site, where the assets for all apps will be stored in a single folder called "assets." Inside this single folder, each app would have its own asset folder. So, if this is my root directory…


 user_guide
 apps_folder (this is where all my application folders live)
 system
 assets

...资产文件夹将这样组织:

...the assets folder will be organized thus:


assets
  myapp1
      js
      img
      css
      media

下面是我的挑战。我想写一个Apache指令,将改写为CSS,JS,PNG和GIF到该应用的有关资产​​目录结尾的文件的所有请求。但是,用户不能知道这些资产在服务器中的确切位置。给你举个例子:

Here is my challenge. I am trying to write an apache directive that would rewrite all requests for files ending in css, js, png and gif to the respective asset directory for that app. But the user cannot know the exact location of those assets in the server. To give you an example:

下面是请求:www.myapp1.com/js/jquery.js

Here is the request: www.myapp1.com/js/jquery.js

该文件位于:资产/ myapp1 / JS

The file is located in: assets/myapp1/js

该指令将检查
一)域名地址
B)文件扩展名

The directive will check for a) the domain address b) file extension

...并根据这些变量,将改写网址,从而达到隐藏你的资产的实际位置,并有可能引用的资产,如果他们都位于网站的根。有没有人做过这样的事情?

...and based on those variables, will rewrite the url, thereby hiding thee real location of the asset, and make it possible to reference assets as if they were all located at the root of the website. Has anyone ever done something like this?

感谢,

推荐答案

这是完全可能的。请参阅Apache重写指南:

This is totally possible. See the Apache rewrite guide:

http://httpd.apache.org/docs/1.3/misc/ rewriteguide.html

您的规则将是这个样子:

Your rule will look something like this:

RewriteCond   %{HTTP_HOST}  \.myapp1\.com$
RewriteRule  ^/js/(.*)\.js$ assets/myapp1/js/$1

玩得开心!

这篇关于HOWTO:重写图片,CSS和每个应用程序的请求JS把不同的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆