使用 mod-rewrite 将 jquery.js 的请求重定向到 GoogleAPI 缓存
我们的 Linux 服务器配备 Apache 2.x、Plesk 8.x,托管着许多电子商务网站。为了利用浏览器缓存,我们希望使用 Google 提供的 jquery.js 副本。
因此,在每个域的 vhost.conf 文件中,我们可以使用以下 RewriteRule
RewriteCond %{REQUEST_FILENAME} jquery.min.js [nc]
RewriteRule . http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [L]
在 vhost_ssl.conf 中,
RewriteCond %{REQUEST_FILENAME} jquery.min.js [nc]
RewriteRule . https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [L]
现在这些规则在每个域的各个 vhost.conf 文件中运行良好。然而,我们托管了 200 多个域,我希望它们能够工作,但似乎无法让它们在 httpd.conf 文件中全局工作。
挑战如下:
- 让重写规则在 httpd.conf 中工作
- 检测 HTTPS 是否打开,如果打开并且是安全页面,则重写为...
- 每个单独的域仍将有其自己的自定义 mod 重写规则。哪些规则优先 - 全局规则还是每个域规则?它们结合了吗?如果我在全局 httpd.conf 中添加“RewriteEngine On”指令,然后在 vhost.conf 中再次添加“RewriteEngine On”指令,可以吗?
请让我知道你们的建议是什么。迫切需要解决这个问题。
Our Linux server with Apache 2.x, Plesk 8.x hosts a number of e-commerce websites. To take advantage of browser caching we would like to use Google's provided copy of jquery.js.
Hence in the vhost.conf file of each we can use the following RewriteRule
RewriteCond %{REQUEST_FILENAME} jquery.min.js [nc]
RewriteRule . http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [L]
And in vhost_ssl.conf
RewriteCond %{REQUEST_FILENAME} jquery.min.js [nc]
RewriteRule . https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [L]
OK now these rules work fine in the individual vhost.conf files of each domain. However we host over 200 domains, I would like for them to work but cannot seem to get them to work globally in the httpd.conf file.
Challenges are the following:
- Get the rewriterule to work in httpd.conf
- Detect if HTTPS is on, and if it is and the is is a secure page, rewrite to ...
- Each individual domain will still have it's own custom mod-rewrite rules. Which rules take precedence - global or per-domain? Do they combine? Is it ok if I have the "RewriteEngine On" directive in the global httpd.conf and then again in the vhost.conf?
Please let me know what your guys' suggestions are. Desperate for a solution to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意 Gumbo 的观点,但你可以这样做:
正如
:
这可以通过查看 %{HTTP_HOST} 来完成:
您还应该转义点,并且您使用的 RewriteCond 是不必要;您可以在 RewriteRule 中执行此操作。
它将被添加到虚拟主机的 mod_rewrite 配置之前。
I agree with Gumbo, but here's how you can do it:
As is clearly stated in the manual:
This can be done by looking at %{HTTP_HOST}:
You should also escape the dots and teh RewriteCond you use is unnecessary; you can do it in the RewriteRule.
It will be prepended to the virtual host's mod_rewrite configuration.