[SOLVED] Replace URL Variable Value?

CLOSED

[SOLVED] Replace URL Variable Value?

Postby linux4me » Sat Feb 20, 2010 4:16 pm

I have typical PHP URL's with a variable called "Itemid" and need to redirect all the pages with a URL containing Itemid=194 to Itemid=1, preserving the rest of the query string. For example, if I have a URL like this:

http://www.mydomain.com/index.php?variable1=2&variable2=3&Itemid=194


I need the URL to be:

http://www.mydomain.com/index.php?variable1=2&variable2=3&Itemid=1


I have tried this:

Code: Select all
RewriteCond %{QUERY_STRING} ^((.*&)?Itemid=194)(&.*)?$ [NC]
RewriteRule ^(index\.php)$ /$1?%1%3 [R=301,L]

but I'm getting an endless loop. The other catch is that the Itemid may not be the last variable in the query string.

What would the redirect be to change all the Itemid=194 to Itemid=1 and leave all other Itemid's unaffected?

TIA
Last edited by linux4me on Sat Feb 20, 2010 7:10 pm, edited 1 time in total.
linux4me
 
Posts: 4
Joined: Sun May 18, 2008 10:52 am

Re: Replace URL Variable Value?

Postby linux4me » Sat Feb 20, 2010 7:09 pm

I think I finally figured it out.

I ended up using the following:
Code: Select all
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)Itemid=194(&.*)?$
RewriteRule ^index\.php$ /index.php?%1Itemid=1%3 [L,R=301]
linux4me
 
Posts: 4
Joined: Sun May 18, 2008 10:52 am


Return to New Threads/Problems

Who is online

Users browsing this forum: No registered users and 3 guests

cron