1

I have a list of urls to redirect. A lot of them include query parameters.

So, for example, I need to redirect

index.php?id=627&type=98

to

/about-us/contact/

I thought that the following would work:

RewriteCond %{QUERY_STRING} "^id=627&type=98$" [NC]
RewriteRule "^index\.php" "/about-us/contact/?" [NC,R,L]

But it is not working. What is wrong with the Rewrite Rule?

1 Answer 1

1

Try not to use quoted strings:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=627&type=98$ [NC]
RewriteRule ^index\.php$ /about-us/contact/? [NC,R,L]

To put in site config:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=627&type=98$ [NC]
RewriteRule ^/index\.php$ /about-us/contact/? [NC,R,L]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that actually works. I had it without quotes before, but then I had a / at the beginning of the RewriteSource. Such a stupid mistake... Also it seems the rules don't work in the site config in apache, only in the .htaccess
If you want to put them in site config (recommended), I've added the subsection for that.

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.