简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM