user1078494
user1078494

Reputation: 509

htaccess redirect dynamic URL to another dynamic URL

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?

Upvotes: 1

Views: 132

Answers (2)

anubhava
anubhava

Reputation: 784958

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]

Upvotes: 1

ste1inbeck
ste1inbeck

Reputation: 315

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]

Upvotes: 0

Related Questions