1

I need to redirect one dynamic URL to another, but with slightly changed parameters. This is the original URL:

http://www.EXAMPLE.com/index.php?main_page=index&cPath=5

and it needs to be redirected to

http://www.EXAMPLE.com/index.php?main_page=index&cPath=25

I have tried so many different variations, but not one seemed to work.

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$
RewriteRule ^/(index\.php|)$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [L,R=301]

I'm going crazy with this... Can anyone please point me in the right direction and tell me what I'm doing wrong?

2 Answers 2

1

I believe leading slash is the problem in your pattern. Try this rule in your root .htaccess:

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$ [NC]
RewriteRule ^/?(index\.php)?$ /$1?main_page=index&cPath=25 [NC,L,R=301]
Sign up to request clarification or add additional context in comments.

1 Comment

aaaah, such a beautiful solution, thank you so much!
0

Maybe without condition?

RewriteEngine on
rewriterule ^index.php?main_page=index&cPath=5$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [r=301,nc]

1 Comment

QUERY_STRING is not available in RewriteRule, because RewriteRule deals with the path, so RewriteCond should be used.

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.