PDA

View Full Version : RewriteRule for extended public folder


cbergy
05-14-2007, 06:39 PM
Hey guys,

I've had a client request their own directory within my Rails application where they can store images and html files. What I've setup (using Capistrano) is a shared directory called custom, and a symlink in my rails app's public directory pointing to this new 'custom' directory.

I'm attempting to setup a RewriteRule which will forward all requests for http://domain/custom to http://domain/custom/index.html

Using the basic index.html call in Rails as a template, I've worked out this:


RewriteRule ^/custom$ /custom/index.html [QSA]


However it doesn't seem to work the way I'd like it do. Any suggestions would definitely be appreciated, thanks!

Matt
05-14-2007, 07:06 PM
RewriteRule ^$ /custom/index.html [L]

That'll do it.

cbergy
05-14-2007, 07:54 PM
Nope, that one didn't seem to want to do it either. Here's the extent of my mod_rewrite parameters:


# Mod-rewrite Options
RewriteEngine On

RewriteBase /

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

Matt
05-15-2007, 01:55 AM
Nope, that one didn't seem to want to do it either. Here's the extent of my mod_rewrite parameters:


# Mod-rewrite Options
RewriteEngine On

RewriteBase /

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

Ta-da. QSA (query string append) won't matter on a static HTML page. L (last) means to stop processing subsequent rules and end if that rule is matched. If you don't use the L flag, then the request cascades down to the check for file existence (REQUEST_FILENAME line), which doesn't exist thus that condition is triggered and sent to dispatch.fcgi for processing.

Edit: wait, did you want to send /custom/* to /custom/index.html or just send /custom/ to /custom/index.html? My solution handles case A. Also, where would this .htaccess file be residing, under / or /custom/?

cbergy
05-15-2007, 02:29 AM
I only want to send /custom to /custom/index.html, anything else in /custom/* works the way it should.

It's currently residing in /, and not /custom. For some reason I only associated .htaccess files with the root dir in my mind.

Yeah, when I pull out the bottom three lines (with the two running the dispatcher) it works great. I also assumed that it would hit the first rewriterule:


RewriteRule ^/custom$ /custom/index.html

...And use that before it hit the dispatcher.

cbergy
05-15-2007, 01:36 PM
Fixed! As soon as I through the RewriteRule in the /custom dir it worked.

Thanks Matt!