Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite Help

         

danbb

10:29 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Hello All

Currently i have the following mod rewrite

RewriteRule ^site/(.*)$ /site?page=$1.php

so if you go to /site/mrtg/mrtg it will rewrite to site?page=mrtg/mrtg.php and the file called site will output my design and also include the mrtg file in there

Now i need to include php variables in there as well so basically visiting /site/mrtg/mrtg?1=1 converts tp site?page=mrtg/mrtg.php&1=1

Is this possible?

jdMorgan

10:55 pm on Feb 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, see RewriteCond [httpd.apache.org], and use it to check the variable %{QUERY_STRING} and create a back-reference to it. You'd then dereference it in RewrteRule using %1 -- just like you use $1 for back-references created in RewriteRule.

Jim

danbb

7:05 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



I presume the rewrite condition will be to check to see if a variable has been sent and the rule will rewrite it, but its the rule part of it i'm not sure about...

Caterham

9:00 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



I assume that you'd like to append the query string from the substitution (right part of the RWRule) - in this case page=mrtg/mrtg.php - with the initial one 1=1 which would result a query string passed to /site of page=mrtg/mrtg.php&1=1

You can use the QSA-Flag here. Take a look at the description of RewritRule flags in the mod_rewrite docs.

RewriteRule ^site/(.*)$ /site?page=$1.php [QSA,L]

danbb

10:19 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Thanks mate, that worked

Seemed like a really hard thing at first but QSA flag does it all, guess the wording of it lost me a bit as i'm still a bit of a newbie with it, thanks again :D