2

It sounds like a relatively simple one but here goes.. I have a wordpress website called example.com It has recently been redeveloped using wordpress however the old sites structure used the following www.example.com/?page_id=22 I want to redirect anything after the domain name that contains /?page_id=[any digit] to the homepage, im having great difficulty in accomplishing this and I also think I may have issues because wordpress itself uses the query string page_id before the permalinks redirects kick in, I could be wrong though but any help on removing the query string directly after a domain name would be great especially keeping in mind that it is a wordpress install.

I have tried various iterations that look like the following to no avail

        RewriteCond %{QUERY_STRING}  ^page_id=(.*)$ 
        RewriteRule (.*) http://www.example.com/  [R=301,L]

        RedirectMatch 301 ^/page_id=(.*)$ /

1 Answer 1

2

Try this rule right at top, just below RewriteEngine On line:

RewriteCond %{QUERY_STRING} ^page_id=\d+$ [NC]
RewriteRule ^/?$ /? [R=301,L]

/? will strip off any query string.

Sign up to request clarification or add additional context in comments.

4 Comments

How we can pass specific page id?
@anubhava : this one not working please give better idea
RewriteCond %{QUERY_STRING} ^page_id=([199])+$ [NC] @anubhava This one working but this right?
It should be: RewriteCond %{QUERY_STRING} ^page_id=199$ [NC], feel free to ask a new question if it doesn't work

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.