We have a multi-site install running drupal 7.x where some sites are rooted in / while others are sub-sites in sub-directories. Setting RewriteBase / in /.htaccess causes 404 page not found errors for the sub-sites. I didn't see anywhere in the module readme file or project issue queue any mention of multi-site installs. Does AIS already work with multi-sites and I've just overlooked the documentation?

Since these rewrites are for image files in the files directory, would it be possible to instead add directives to the .htaccess file in /sites/sitename/files/.htaccess?

Comments

spotzero’s picture

I haven't tested it in a while, however AIS should work with multi-site installs, and multi-site installs shouldn't be affected by setting "rewritebase /".

However, it would break things if your sites had different paths based on domain.

For example:

The url to sites 1 is "site1.com/". <- The rewritebase should be /
The url to sites 2 is "site2.com/drupalsite/". <- The rewritebase should be /drupalsite/

In the case above, since the rewritebase can only be correct for one of the sites at a time, one site will always be broken.

I haven't tried moving the rewrite directives into an .htaccess file in /sites/sitename/files, however it may not work. This is because the AIS rewrite directives need to take precedence over the standard Drupal rewrite directives, so I'm not sure off hand is what order the rewrite rule will be processed by apache if we move them around.

thoogend’s picture

Thanks for your reply. The example you gave summarizes precisely the situation we're in. I'm willing to try out a bunch of possible work arounds. We have a development server with a copy of our complicated multi-site install that I could use for testing.

Alternatively, since the new site that needs the AIS module will have a new domain name and correspondingly named VirtualHost block, I could setup a separate DocumentRoot for the new site with an ais-patched .htaccess file and symbolic links back into the main multi-site install directory. Ideally, it would be nice to get the .htaccess rules working for this use case so I don't have to complicate the organization of the file system any further.

Let me know what you think. And thanks!

spotzero’s picture

Based on your setup and access to the webserver config, the easiest solution is probably just to restore your .htaccess file to the original drupal one, and add the AIS htaccess rules directly into the corresponding virtualhost configuration.

If the site using AIS has got its own domain name, adding the AIS rewrites as part of the VirtualHost should get AIS working without affecting any of the other sites.

thoogend’s picture

This morning, I went ahead and setup the new VirtualHost configuration for the site using the ais module. Everything works fine. But as soon as we want to implement the ais module for http://domain.com/site1 and not for http://domain.com/site2, we'll be back at square one with one .htaccess file and the need for two different, conflicting RewriteBases. I'm still willing to help test possible solutions for this use case if you're interested. I've got some experience with .htaccess rewrites, but I don't know how much I could contribute to actually figuring this one out.

spotzero’s picture

If you removed the RewriteBase and did something like this, it shoud work:

Change this:

# AIS: Adaptive Image Style
  RewriteBase /
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

To this:

# AIS: Adaptive Image Style
  RewriteCond %{REQUEST_URI} ^/site1/(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/site1/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]


# AIS: Adaptive Image Style
  RewriteCond %{REQUEST_URI} ^/site2/(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/site2/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]
spotzero’s picture

Status: Active » Closed (fixed)