Hi, Could anyone help me with a RewriteRule problem? What I want to accomplish is that every url except those starting with a known controller will be translated to /page/*the-original-url*/show. Example: jlaine.net/portfolio would be translated to jlaine.net/page/portfolio/show Here''s how I (with no luck) tried to approach the problem: RewriteRule ^((^(admin|collection|image|login|markup|page|stock|fi|en)).*)$ page/$1/show [R] My regexp seems to work fine without the negation, which causes it to break completely. So if anyone with a better regexp grip could help me with this he would earn my eternal gratitude. TIA, Jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
This won''t correct the problem with your RegExp, but why not do this: RewriteRule \ ^(admin|collection|image|login|markup|page|stock|fi|en).*$ \ - [skip=1] RewriteRule ^(.+)$ /page/$1/show [R] Makes the first rule fairly simple and just has it skip the next one. I haven''t tested it, but it should work. Ben On Fri, 7 Jan 2005 23:34:43 +0200, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> Hi, > > Could anyone help me with a RewriteRule problem? > > What I want to accomplish is that every url except those starting with > a known controller will be translated to /page/*the-original-url*/show. > > Example: jlaine.net/portfolio would be translated to > jlaine.net/page/portfolio/show > > Here''s how I (with no luck) tried to approach the problem: > > RewriteRule > ^((^(admin|collection|image|login|markup|page|stock|fi|en)).*)$ > page/$1/show [R] > > My regexp seems to work fine without the negation, which causes it to > break completely. So if anyone with a better regexp grip could help me > with this he would earn my eternal gratitude. > > TIA, > Jarkko > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Jarkko, I don''t know if this will work or not, but perhaps you could use a RewriteCond directive for this, something like this: RewriteCond %{REQUEST_URI} !^(admin|collection|image|login|markup|page|stock|fi|en).* RewriteRule ...... http://httpd.apache.org/docs/mod/mod_rewrite.html ----- Original Message ----- From: "Jarkko Laine" <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Sent: Friday, January 07, 2005 2:34 PM Subject: [Rails] RewriteRule problem> _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks for the help, Ben and Jeffrey, I feel I''m getting closer, but am not quite there yet. I figured the following would be the best way to handle this: <snip> RewriteRule ^(admin|collection|image|login|markup|page|stock|fi|en).*$ - [skip=1] RewriteRule ^([-_a-zA-Z0-9]+)$ ?controller=page&action=show&action_prefix=$1 [QSA,L] # Default rewriting rules. ... </snip> (the whole file can be found here: http://rafb.net/paste/results/NU4ys540.html) Now valid controllers (admin, collection, etc.) work perfect. However, it seems that the latter rule seems to always be skipped. Therefore, with an address like /test/, I get this error: No such file to load -- test_controller.rb I don''t get this. The mod_rewrite docs clearly state that "[skip] flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches". In this case, the rule shouldn''t match but it''s still skipping. Anyone understand what''s happening? //jarkko On 7.1.2005, at 23:54, Ben Schumacher wrote:> This won''t correct the problem with your RegExp, but why not do this: > > RewriteRule \ > ^(admin|collection|image|login|markup|page|stock|fi|en).*$ \ > - [skip=1] > RewriteRule ^(.+)$ /page/$1/show [R] > > Makes the first rule fairly simple and just has it skip the next one. > > I haven''t tested it, but it should work. > > Ben > > > On Fri, 7 Jan 2005 23:34:43 +0200, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> > wrote: >> Hi, >> >> Could anyone help me with a RewriteRule problem? >> >> What I want to accomplish is that every url except those starting with >> a known controller will be translated to >> /page/*the-original-url*/show. >> >> Example: jlaine.net/portfolio would be translated to >> jlaine.net/page/portfolio/show >> >> Here''s how I (with no luck) tried to approach the problem: >> >> RewriteRule >> ^((^(admin|collection|image|login|markup|page|stock|fi|en)).*)$ >> page/$1/show [R] >> >> My regexp seems to work fine without the negation, which causes it to >> break completely. So if anyone with a better regexp grip could help me >> with this he would earn my eternal gratitude. >> >> TIA, >> Jarkko >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://odesign.fi >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sat, 8 Jan 2005 14:03:10 +0200, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> Now valid controllers (admin, collection, etc.) work perfect. However, > it seems that the latter rule seems to always be skipped. Therefore, > with an address like /test/, I get this error: > > No such file to load -- test_controller.rbActually it seems to be doing what it''s supposed to. Here''s what''s happening, with a couple more line from your file: <snip> # Add missing slash RewriteRule ^([-_a-zA-Z0-9]+)$ /$1/ [R] RewriteRule ^(admin|collection|image|login|markup|page|stock|fi|en).*$ - [skip=1] RewriteRule ^([-_a-zA-Z0-9]+)$ ?controller=page&action=show&action_prefix=$1 [QSA,L] # Default rewriting rules. ... RewriteRule ^([-_a-zA-Z0-9]+)/$ ?controller=$1&action=index [QSA,L] </snip> When you go to yoursite.com/test and mod_rewrite walks the list, it''ll match the first rule there and add the trailing slash, which turns to request into yoursite.com/test/. As it continues down the list, it doesn''t match the skip rule and keeps going to your new rule. However, it doesn''t match this one either, because the trailing slash is not accepted as part of that regex, so it''ll just keep going on until it eventually matches the 3rd rule after the "Default rewriting rules" comment which causes it to treat "test" as a controller. All you need to do is change that new rule you added to: RewriteRule ^([-_a-zA-Z0-9]+)/$ ?controller=page&action=show&action_prefix=$1 [QSA,L] Cheers, Ben> On 7.1.2005, at 23:54, Ben Schumacher wrote: > > > This won''t correct the problem with your RegExp, but why not do this: > > > > RewriteRule \ > > ^(admin|collection|image|login|markup|page|stock|fi|en).*$ \ > > - [skip=1] > > RewriteRule ^(.+)$ /page/$1/show [R] > > > > Makes the first rule fairly simple and just has it skip the next one. > > > > I haven''t tested it, but it should work. > > > > Ben > > > > > > On Fri, 7 Jan 2005 23:34:43 +0200, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> > > wrote: > >> Hi, > >> > >> Could anyone help me with a RewriteRule problem? > >> > >> What I want to accomplish is that every url except those starting with > >> a known controller will be translated to > >> /page/*the-original-url*/show. > >> > >> Example: jlaine.net/portfolio would be translated to > >> jlaine.net/page/portfolio/show > >> > >> Here''s how I (with no luck) tried to approach the problem: > >> > >> RewriteRule > >> ^((^(admin|collection|image|login|markup|page|stock|fi|en)).*)$ > >> page/$1/show [R] > >> > >> My regexp seems to work fine without the negation, which causes it to > >> break completely. So if anyone with a better regexp grip could help me > >> with this he would earn my eternal gratitude. > >> > >> TIA, > >> Jarkko > >> > >> -- > >> Jarkko Laine > >> http://jlaine.net > >> http://odesign.fi > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >> > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >