Forum Moderators: phranque

Message Too Old, No Replies

variables in mod-rewrite

         

sssweb

4:04 pm on Jun 30, 2010 (gmt 0)

10+ Year Member



Can someone please tell me what the ".$2" is for in:

RewriteRule (.*) /pagemaker.php?url=$1.$2 [NC,L]


This code is supposed to send the requested page filename (var 'url') to a page generator file. Var $1 does this, but with ".$2" at the end, I get results for $url like:

file.htm.
page.html.
doc.php.

There's a trailing period and never a second variable, even if the page requested is:

doc.php?test=1&new=2

g1smd

6:46 pm on Jun 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's because the (.*) backreference "makes" the $1 data and there is nothing to "make" the $2 data.

The $2 will always be blank.

Remove the .$2 or change the (.*) pattern to be more specific.

As written, the rule will make an infinite loop, and will also rewrite requests for images, CSS and JS files, robots.txt, etc, to your script.

The (.*) pattern is too wide. It needs to be more specific, matching only "page" URLs, and not the other stuff.

sssweb

7:22 pm on Jun 30, 2010 (gmt 0)

10+ Year Member



Okay, I understand now -- thanks.