0

My Question is similar (almost the same) to another question asked here: but with a twist.

Does anybody have some working Apache mod_rewrite rules that enable Phusion Passenger (mod_rails) to use a non-default location for the page cache within a Rails application? I'd like the cached files to go in /public/cache rather than the default of /public.

In my case I have 2 custom directories. "/public/www.MYSITE.com/" and "/public/m.MYSITE.com" for mobile requests.

This particular mod_rewrite code works for me ONLY for www.MYSITE.com requests:

RewriteRule ^$ /www.MYSITE.com/index.html [QSA]
RewriteRule ^([^.]+)$ /www.MYSITE.com/$1.html [QSA]

Now is there a way to take the www.MYSITE.com or m.MYSITE.com from the incoming url and substitute it for the directory location to look for the cached page? Everything about the url for both mobile and www requests are the same except for the prefix of the host "m" for mobile browsers and "www" for everything else.

Just to clarify I have mod_rewrite conditions/rules to detect mobile browser which works fine I just need to tell apache which cache directory it is located in based on the subdomain of the request.

Ranknoodle
  • 103
  • 2

1 Answers1

0

RewriteCond can look at the host header that the request came in with.

Something like this:

RewriteCond %{HTTP_HOST} ^m [NC]
RewriteRule ^$ /m.MYSITE.com/index.html [QSA]
RewriteCond %{HTTP_HOST} ^m [NC]
RewriteRule ^([^\.]+)$ /m.MYSITE.com/$1.html [QSA]

RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^$ /www.MYSITE.com/index.html [QSA]
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^([^\.]+)$ /www.MYSITE.com/$1.html [QSA]

But, since this is handling the different sites out of completely different directories, why not just do two different VirtualHost configurations for the hosts, with different DocumentRoot settings?

Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • I tried the code and it worked but only if there was page.html in the cache directory otherwise it would give me a 404 error when it should hit the app to generate the page on the request if the page.html didn't exist. I think the VirtualHost idea is interesting but I want to serve every request from the same app – Ranknoodle Nov 16 '11 at 22:26
  • Well, sounds the mod_rewrite's doing all that it needs to do - is the request to the cache location being properly handled by the dynamic content handler? Or do we need to have it check if the file exists, and not do the rewrite in that case? – Shane Madden Nov 16 '11 at 22:32