1

I have pages with the following parameters: /article.php?sid=123&cat1=en

I need to change that cat1 to cat and redirect to the same address.

I've tried RewriteRule ^/article.php?sid=(.*)&cat1=(.*)$ /article.php?sid=$1&cat=$2 [R=301,L] but it's not working.

1 Answer 1

1

You can use this rule to match & replace a given query parameter at any position.

Keep this rule as your very first rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?cat1=([^&]*(?:&.*)?)$ [NC]
RewriteRule ^article\.php$ %{REQUEST_URI}?%1cat=%2 [R=301,NE,L]
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. How would I go around if I had just one parameter say: /article.php?cat1=en?
I made a minor update. http://localhost/article.php?cat1=en will be redirected to http://localhost/article.php?cat=en

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.