2

I would like to change the URL

/index.php?main_page=product_info&cPath=1&products_id=4 

to

/index.php?main_page=product_info&cPath=141&products_id=302

I have tried

RewriteRule ^products_id=4$ products_id=302

but that doesn't seem to match.

My .htaccess 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.)

6
  • That's because you have it backwards. Should be RewriteRule ^products_id=302$ products_id=4 Commented Sep 3, 2016 at 21:35
  • Did you put [L,R=301] after the rule? Commented Sep 3, 2016 at 22:09
  • Post all relevant rewrite options you have in .htaccess Commented Sep 3, 2016 at 22:37
  • You also need Options +FollowSymLinks otherwise mod_rewrite won't work. Commented Sep 4, 2016 at 4:25
  • 2
    The unreliability of clicking on links with the rewriterule you attempted (which looks correct) could be due to your browser caching a previous 301 redirect. They tend to aggressively cache redirects. Test this out in a different browser or private/incognito browsing window. That's always essential when debugging redirects. Commented Sep 4, 2016 at 14:23

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.