PDA

View Full Version : RewriteRule - cant get it right


NancyJ
01-09-2007, 04:30 PM
I'm trying to use a rewrite rule to redirect users to the right pages (since my client changed their pages all around) but its just not working
We're doing the same thing for seo friendly links and that works fine but
RewriteRule ^oldpage.php?pid=([0-9]+)&flag=true /newpage.php?pid=$1

Just isnt working

RewriteRule ^oldpage.php/([0-9]+) /newpage.php?pid=$1

works fine but thats obviously not the right path.

I've also tried escaping the ? and = like

RewriteRule ^oldpage.php\?pid\=([0-9]+)\&flag=true /newpage.php?pid=$1

But that didnt work either... what am I doing wrong?

bcarl314
01-09-2007, 05:17 PM
I think the only thing you need to escape is meta chars (.?*) so try this...


RewriteRule ^oldpage\.php\?pid=([0-9]+)&flag=true /newpage.php?pid=$1


I'm trying to use a rewrite rule to redirect users to the right pages (since my client changed their pages all around) but its just not working
We're doing the same thing for seo friendly links and that works fine but
RewriteRule ^oldpage.php?pid=([0-9]+)&flag=true /newpage.php?pid=$1

Just isnt working

RewriteRule ^oldpage.php/([0-9]+) /newpage.php?pid=$1

works fine but thats obviously not the right path.

I've also tried escaping the ? and = like

RewriteRule ^oldpage.php\?pid\=([0-9]+)\&flag=true /newpage.php?pid=$1

But that didnt work either... what am I doing wrong?

NancyJ
01-09-2007, 05:29 PM
I tried that too and it didnt work. Not escaping the . works fine but when I add the ? it doesnt work. Even if I escape it.

schleppel
01-09-2007, 09:01 PM
RewriteRules only match from the directory where the .htaccess file is located to the ?. Query strings are matched with RewriteConds and %{QUERY_STRING}.

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?flag=true(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?pid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^oldpage\.php$ /newpage.php?pid=%2 [L]