Scott Wilson Scott Wilson - 1 year ago 128
Apache Configuration Question

.htaccess redirect to change parameter value

I would like to change the URL




I have tried

RewriteRule ^products_id=4$ products_id=302

but that doesn't seem to match.

file currently contains

RewriteEngine on
Options +FollowSymLinks
RewriteRule ^products_id=302$ products_id=4 [L,R=301]

It would seem like I could use something like

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)products_id=4(&.*)?$
RewriteRule ^index\.php$ /index.php?%1products_id=302%3 [L,R=301]

but that doesn't work reliably. (If I click on a link, it doesn't work, but if I enter that URL in the address bar, it does.)

Answer Source

Try the following rule :

RewriteEngine on

RewriteCond %{THE_REQUEST} /index\.php\?main_page=([^&]+)&cPath=1&products_id=4\sHTTP [NC]
RewriteRule ^ /index.php?main_page=%1&cPath=141&products_id=302 [L,R]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download