Is there a way of preventing rewrite rules from rewriting requests to domain root (http://www.example.com/) to "/controller/action"? I want to hace a "main_controller.rb" hadle, among other actions, "index" without showing the user "http://www.example.com/main/index" but simply "http://www.example.com/". I tried adding the following after lines 23, 33 and 39 respectively: RewriteRule ^fcgi/$ /dispatch.fcgi?controller=main&action=index [QSA] [L] RewriteRule ^mruby/$ /dispatch.rb?controller=main&action=index [QSA] [L] RewriteRule ^$ / [R] ...bu nothing. Actually I get "Redirection limit for this url exceeded. Unable to load the requested page. This may be caused by cookies that are blocked." I understand the message and why it happens but don''t know how to get what I want. Has anyone tried tried doing this?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Luis G. Gómez wrote: | I want to hace a "main_controller.rb" hadle, among other actions, | "index" without showing the user "http://www.example.com/main/index" but | simply "http://www.example.com/". ~ RewriteRule ^$ /dispatch.cgi?controller=main&action=index [QSA,L] For all its power, mod_rewrite can be pretty cryptic. The options at the end of the rule (R, PT, L, etc) are critical. Check out the mod_rewrite guide (http://httpd.apache.org/docs-2.0/misc/rewriteguide.html) for a cookbook of common problems & solutions. Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBnm08AQHALep9HFYRAunHAKC89mGkCEk0bgtQnsV5L1I9ykJIZACfY2CL Nb0et90EIEGfA41lLvufvzg=iaU6 -----END PGP SIGNATURE-----
Or even easier : RewriteRule ^$ /controller/actionofmychoice Put this before the other rewrite rules. Rules are chained, so a later rule will make the correct transformation out of it. On Fri, 19 Nov 2004 14:01:32 -0800, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Luis G. Gómez wrote: > | I want to hace a "main_controller.rb" hadle, among other actions, > | "index" without showing the user "http://www.example.com/main/index" but > | simply "http://www.example.com/". > > ~ RewriteRule ^$ /dispatch.cgi?controller=main&action=index [QSA,L] > > For all its power, mod_rewrite can be pretty cryptic. The options at > the end of the rule (R, PT, L, etc) are critical. Check out the > mod_rewrite guide > (http://httpd.apache.org/docs-2.0/misc/rewriteguide.html) for a cookbook > of common problems & solutions. > > Best, > jeremy > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.6 (Darwin) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFBnm08AQHALep9HFYRAunHAKC89mGkCEk0bgtQnsV5L1I9ykJIZACfY2CL > Nb0et90EIEGfA41lLvufvzg> =iaU6 > -----END PGP SIGNATURE----- > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://blog.leetsoft.com
I''m confused. There is a "RewriteRule ^$ /controller/action [R]" on line 23 of a fresh intalation I just made. I uncommented it and changed it to point to "RewriteRule ^$ /main/index [R]" but going to "http://www.example.com/" keeps taking me to "http://www.example.com/_doc/index.html" I do have a "main_controller.rb" under app/ that contains: require ''abstract_application'' require ''main_helper'' class MainController < AbstractApplicationController include MainHelper def index render_text "Finally!!!" end end But nothing... :S Thank you. Tobias Luetke wrote:> Or even easier : > > RewriteRule ^$ /controller/actionofmychoice > > Put this before the other rewrite rules. Rules are chained, so a later > rule will make the correct transformation out of it. > > > On Fri, 19 Nov 2004 14:01:32 -0800, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote: > >>-----BEGIN PGP SIGNED MESSAGE----- >>Hash: SHA1 >> >>Luis G. Gómez wrote: >>| I want to hace a "main_controller.rb" hadle, among other actions, >>| "index" without showing the user "http://www.example.com/main/index" but >>| simply "http://www.example.com/". >> >>~ RewriteRule ^$ /dispatch.cgi?controller=main&action=index [QSA,L] >> >>For all its power, mod_rewrite can be pretty cryptic. The options at >>the end of the rule (R, PT, L, etc) are critical. Check out the >>mod_rewrite guide >>(http://httpd.apache.org/docs-2.0/misc/rewriteguide.html) for a cookbook >>of common problems & solutions. >> >>Best, >>jeremy >>-----BEGIN PGP SIGNATURE----- >>Version: GnuPG v1.2.6 (Darwin) >>Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org >> >>iD8DBQFBnm08AQHALep9HFYRAunHAKC89mGkCEk0bgtQnsV5L1I9ykJIZACfY2CL >>Nb0et90EIEGfA41lLvufvzg>>=iaU6 >>-----END PGP SIGNATURE----- >> >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> > > >
On Saturday 20 November 2004 01:32, Luis G. Gómez wrote:> I''m confused. > > There is a "RewriteRule ^$ /controller/action [R]" on line 23 of > a fresh intalation I just made. I uncommented it and changed > it to point to "RewriteRule ^$ /main/index [R]" but going to > "http://www.example.com/" keeps taking me to > "http://www.example.com/_doc/index.html" >Put something like: RewriteLog /var/log/rewrite.log RewriteLogLevel 5 in your main httpd.conf. It explains in very much detail what mod_rewrite is doing. Cheers, Han Holl
On Nov 20, 2004, at 4:09, Han Holl wrote:> Put something like: > > RewriteLog /var/log/rewrite.log > RewriteLogLevel 5 > > in your main httpd.conf. > It explains in very much detail what mod_rewrite is doing.I never will understand why folks like this rewrite stuff: why would you want to put all this effort into using an obscure language that isn''t portable to other web environments? I just don''t see why the dispatchers can''t call out to some Ruby code that I can write, which takes a raw URL and converts it into a dispatchable one. That way I''d have something that was easy to understand, local to the application, and portable across web environments. All it needs to be is a file (say in app/rewrite) containing a module module Rails module Rewrite def Rewrite.rewrite(raw_url) if raw_url =~ /..../ ... else ... end end or def rewrite(raw_url) case raw_url when /..../ etc The common dispatcher support code could provide a default variant of this, called if the application doesn''t implement the rewrite itself. A slightly fancier version might be to have the rewrite partially fill in a request object, but I personally think that this is best left up to the dispatcher code: returning a new URL is better encapsulation, if slightly more work for the dispatcher. Cheers Dave
>From: Dave Thomas <dave-kbbdpT5sCmpWk0Htik3J/w@public.gmane.org> >... I just don''t see why the dispatchers can''t call out to some Ruby code >that I can write, which takes a raw URL and converts it into a dispatchable >one.I agree 100%. _________________________________________________________________ It''s fast, it''s easy and it''s free. Get MSN Messenger today! http://www.msn.co.uk/messenger
On Saturday 20 November 2004 16:39, Dave Thomas wrote:> > I never will understand why folks like this rewrite stuff: why would > you want to put all this effort into using an obscure language that > isn''t portable to other web environments? I just don''t see why the > dispatchers can''t call out to some Ruby code that I can write, which > takes a raw URL and converts it into a dispatchable one. That way I''d > have something that was easy to understand, local to the application, > and portable across web environments.Mostly agreed. However, it''s possible (though not much discussed in relation to rails) that the rails application is intended to be part of a larger website. There may be static content, stylesheets, javascript, graphics or even sound that you can deliver much faster without going through the rails framework. And of course choosing between fcgi for production use and plain cgi for development is nice. Cheers, Han Holl