You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Peter Kay <pe...@yahoo.com> on 2009/06/29 18:13:16 UTC

[users@httpd] Internal Recursion with mod_rewrite

Hello all,

I'm embedding Gallery2 in PmWiki, and trying to get rewrite rules to work for both of the applications.  Each has separate rewrite rules, but I'm having trouble combining them...I seem to have a problem with recursive internal redirects, which I don't understand, as every rule uses the [L] command.

The rules are contained in an .htaccess file.

My .htaccess file:


<IfModule mod_rewrite.c> 
     RewriteEngine On 

     # Send requests without parameters to pmwiki.php. 
     RewriteRule ^$           pmwiki.php  [L] 

     RewriteCond %{REQUEST_FILENAME} -f [OR] 
     RewriteCond %{REQUEST_FILENAME} -d [OR] 
     RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php 
     RewriteRule .   -   [L] 


     RewriteCond %{THE_REQUEST} /Main/Gallery/([^?]+)(\?.|\ .) 
     RewriteRule .   /Main/Gallery?g2_path=%1   [QSA,L] 
     # Send any other requests to pmwiki.php, appending the query string 
part. 
     RewriteRule ^([A-Z0-9\xa0-\xff].*)$ pmwiki.php?n=$1  [QSA,L] 
</IfModule> 

I'm using Apache 2.2 (as a side question - should rewrite rules that work for 2.2 work for other versions?).

The pmwiki requests work fine (so website.net/ works) as do links to any pmwiki stuff (so website.net/Main/Gallery/ pulls up the correct embedding pmwiki request), but...

If I try to go to website.net/Main/Gallery/test1 it doesn't work.  I expect it to get rewritten as website.net/Main/Gallery?g2_path=test1 (which does work if I go there directly).

I get a 500 Internal Server Error, and the error_log gives:

   Request exceeded the limit of 10 internal redirects due to probable 
   configuration error. Use 'LimitInternalRecursion' to increase the 
   limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: 
   website.net/Main/Gallery 

I'm a bit baffled, as all the rules have [L].  Any ideas?

Thanks,

--Peter Kay


      

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Internal Recursion with mod_rewrite

Posted by Peter Kay <pe...@yahoo.com>.
----- Original Message ----

> From: Eric Covener <co...@gmail.com>
> To: users@httpd.apache.org
> Sent: Tuesday, June 30, 2009 5:24:44 PM
> Subject: Re: [users@httpd] Internal Recursion with mod_rewrite
> 
> On Tue, Jun 30, 2009 at 5:24 PM, Eric Covenerwrote:
> > On Tue, Jun 30, 2009 at 2:14 PM, Peter Kaywrote:
> >> Is adding another RewriteCond %{THE_REQUEST} !/Main/Gallery the canonical way 
> to go?  Or is there some way to turn off the re-injection?
> >
> > That's the normal pattern (but with %{REQUEST_URI} more carefully
> > anchored maybe)

!=/Main/Gallery, as it turns out (slash required) to get:

    RewriteCond %{THE_REQUEST} /Main/Gallery/([^?]+)(\?.|\ .)
    RewriteCond %{REQUEST_URI} !=/Main/Gallery
    RewriteRule .   /Main/Gallery?g2_path=%1   [QSA,L]


> Meant to include http://wiki.apache.org/httpd/RewriteLooping


They don't mention on that page that arguments (?g2_path=etc) don't count as URI...  I read the page, and never thought that /Main/Gallery?g2_path=test1/ would match!  I know better now.

Thanks,

--Peter Kay


      

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Internal Recursion with mod_rewrite

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jun 30, 2009 at 5:24 PM, Eric Covener<co...@gmail.com> wrote:
> On Tue, Jun 30, 2009 at 2:14 PM, Peter Kay<pe...@yahoo.com> wrote:
>> Is adding another RewriteCond %{THE_REQUEST} !/Main/Gallery the canonical way to go?  Or is there some way to turn off the re-injection?
>
> That's the normal pattern (but with %{REQUEST_URI} more carefully
> anchored maybe)

Meant to include http://wiki.apache.org/httpd/RewriteLooping

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Internal Recursion with mod_rewrite

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jun 30, 2009 at 2:14 PM, Peter Kay<pe...@yahoo.com> wrote:
> Is adding another RewriteCond %{THE_REQUEST} !/Main/Gallery the canonical way to go?  Or is there some way to turn off the re-injection?

That's the normal pattern (but with %{REQUEST_URI} more carefully
anchored maybe)

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Internal Recursion with mod_rewrite

Posted by Peter Kay <pe...@yahoo.com>.
----- Original Message ----

> I'm embedding Gallery2 in PmWiki, and trying to get rewrite rules to work...

Ok, I think I understand what's going on (after installing a local copy of apache, etc to let me push up the debug levels...I didn't know httpd could crash so easily!):

>      RewriteCond %{THE_REQUEST} /Main/Gallery/([^?]+)(\?.|\ .) 
>      RewriteRule .   /Main/Gallery?g2_path=%1   [QSA,L] 


So, after this, /Main/Gallery/test1/ gets mapped to /Main/Gallery?g2_path=test1/, then (as per the fine print in the 'last rule' section of the mod_rewrite documentation), "the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule."

So, /Main/Gallery gets re-injected (hmm...) and matches /Main/Gallery/ again.  And again.  And Again.

What's the proper way to avoid this?

Is adding another RewriteCond %{THE_REQUEST} !/Main/Gallery the canonical way to go?  Or is there some way to turn off the re-injection?

Thanks,

--Peter Kay


      

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org