views:

101

answers:

1

Hi All,

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:

  1. Get the rewriterule to work in httpd.conf
  2. Detect if HTTPS is on, and if it is and the is is a secure page, rewrite to ...
  3. 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.

+1  A: 

I agree with Gumbo, but here's how you can do it:

1.. Get the rewriterule to work in httpd.conf

As is clearly stated in the manual:

By default, mod_rewrite configuration settings from the main server context are not inherited by virtual hosts. To make the main server settings apply to virtual hosts, you must place the following directives in each section:

RewriteEngine On
RewriteOptions Inherit

 

2.. Detect if HTTPS is on, and if it is and the is is a secure page, rewrite to ...

This can be done by looking at %{HTTP_HOST}:

RewriteCond %{HTTPS} !=on
RewriteRule /jquery\.min\.js$ https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [NC,R=permanent]

RewriteCond %{HTTPS} =on
RewriteRule /jquery\.min\.js$ http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js [NC,R=permanent]

You should also escape the dots and teh RewriteCond you use is unnecessary; you can do it in the RewriteRule.

3.. 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?

It will be prepended to the virtual host's mod_rewrite configuration.

Artefacto
fixed it. thanks Artefacto
Aditya Advani