How to remove Query Strings such as date= or author= from url in Wordpress using htaccess

I used following htacces code for removing date= query string from the URL

RewriteCond %{QUERY_STRING} (?:^|&)date=(.*)$
RewriteRule ^paivamaara/(.*)$ /paivamaara/$1?date=%1 [L,R]

its working on simple PHP file but when applied to Wordpress; its not working anymore.

Please help

Upvotes: 1

Views: 212

Answers (1)

anubhava
anubhava

Reputation: 786091

That rule doesn't look right for removal of date parameter because you are adding it back in target.

You can use this redirect rule just below RewriteEngine On line to remove a specific query parameter:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?date=[^&]*(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=302,NE,L]

# all WP rules come below this line

Note that this rule allows your query parameter to be positioned anywhere in a query string.

Here is regex demo for the regex used above.

Upvotes: 1

Related Questions