简体   繁体   English

如何使用 htaccess 从 Wordpress 中的 url 中删除查询字符串,例如 date= 或 author=

[英]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我使用以下 htacces 代码从 URL 中删除 date= 查询字符串

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

its working on simple PHP file but when applied to Wordpress;它适用于简单的 PHP 文件,但应用于 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.该规则不适合删除date参数,因为您将其添加回目标。

You can use this redirect rule just below RewriteEngine On line to remove a specific query parameter:您可以在RewriteEngine On行下方使用此重定向规则来删除特定的查询参数:

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.这是上面使用的正则表达式的正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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