[Mongrel] Apache Re-Write and Directories

Philip Hallstrom mongrel at philip.pjkh.com
Tue Oct 3 17:01:40 EDT 2006


> Nicely done -- I'll add this to apache page!

Thanks :)  I don't think I thought of it though, but don't remember where 
i saw it..  in case it helps anyone else, here's my full apache config 
that lets rails/php play nice together....

Of course, if you see any problems with this, be sure to let me know so I 
can fix it :)

<VirtualHost *:80>

   ServerName myserver.com
   DocumentRoot /path/to/my/app/public

   <Directory "/path/to/my/app/public">
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
   </Directory>

   <Proxy balancer://mongrel_cluster>
     BalancerMember http://127.0.0.1:8805
   </Proxy>

   RewriteEngine On

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
   RewriteRule ^(.+[^/])$ $1/ [R]

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} \.php
   RewriteRule ^(.*)$ $1 [QSA,L]

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
   RewriteRule ^(.*)$ $1/index.html [QSA,L]

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
   RewriteRule ^(.*)$ $1/index.php [QSA,L]

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
   RewriteRule ^(.*)[^/]$ $1/ [QSA,L]

   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
   RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

   AddOutputFilterByType DEFLATE text/html
   AddOutputFilterByType DEFLATE application/x-javascript
   AddOutputFilterByType DEFLATE text/css
   AddOutputFilterByType DEFLATE text/plain
   AddOutputFilterByType DEFLATE text/xml
   AddOutputFilterByType DEFLATE application/xml
   AddOutputFilterByType DEFLATE application/xhtml+xml

   BrowserMatch ^Mozilla/4 gzip-only-text/html
   BrowserMatch ^Mozilla/4.0[678] no-gzip
   BrowserMatch bMSIE !no-gzip !gzip-only-text/html

   php_value include_path /path/to/my/app/php:/usr/local/lib/php:.
   php_value auto_prepend_file /path/to/my/app/php/auto_prepend.php

   # this not only blocks access to .svn directories, but makes it appear
   # as though they aren't even there, not just that they are forbidden
   <DirectoryMatch "^/.*/\.svn/">
     ErrorDocument 403 /404.html
     Order allow,deny
     Deny from all
     Satisfy All
   </DirectoryMatch>

</VirtualHost>


>
> # if the directory exists, add trailing slash
>>    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
>>    RewriteRule ^(.+[^/])$ $1/ [R]
>
>
>
> On 10/3/06, Philip Hallstrom <mongrel at philip.pjkh.com> wrote:
>>> I am using the 'default' Apache 2.2 mod_rewrite rules suggested from the Web
>>> site and they are working.
>>>
>>> One thing related to static (non cluster directed) resources:
>>>
>>> If I have a directory in public called 'static', if I request it as follows:
>>>
>>> http://www.domain.com/static/  - then it works
>>>
>>> If I request it as:
>>>
>>> http://www.domain.com/static - then it does not work as it gets directed to
>>> the cluster.
>>>
>>> How can I change my rewrite rules to have both of the above URLs be served
>>> by the static resource via Apache, not by Mongrel?
>>
>> Add this to the beginning...
>>
>>    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
>>    RewriteRule ^(.+[^/])$ $1/ [R]
>>
>>
>>
>>>
>>> Rewrite rules:
>>>
>>>  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
>>>  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
>>>  RewriteRule ^.*$ /maintenance.html [L]
>>>  # Rewrite index to check for static index.html
>>>  RewriteRule ^/$ /index.html [QSA]
>>>  # Rewrite to check for Rails cached pages with .html extentions
>>>  RewriteRule ^([^.]+)$ $1.html [QSA]
>>>  # All dynamic requests get sent to the cluster
>>>  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
>>>  RewriteRule ^/(.*)$ balancer://cluster%{REQUEST_URI} [P,QSA,L]
>>>
>>> Thanks!!!
>>>
>>> Hunter
>>>
>>>
>>> _______________________________________________
>>> Mongrel-users mailing list
>>> Mongrel-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/mongrel-users
>>>
>> _______________________________________________
>> Mongrel-users mailing list
>> Mongrel-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/mongrel-users
>>
>
>
> -- 
> Charles Brian Quinn
> self-promotion: www.seebq.com
> highgroove studios: www.highgroove.com
> slingshot hosting: www.slingshothosting.com
> _______________________________________________
> Mongrel-users mailing list
> Mongrel-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-users
>


More information about the Mongrel-users mailing list