将问号 URL 重定向到原始 URL

Redirect question mark URL to the original URL

我想重定向以下URL

https://www.example.com/vmi10/? to https://www.example.com/vmi10/

这是一个 WordPress 网站。我怎样才能做到这一点?非常感谢您提供的任何帮助。

基本上你想从 url 中删除空查询字符串,我们在 RewriteCond 条件模式中使用 ^$,如下所示:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) /? [R=301,L]

这将重定向 https://www.example.com/vmi10/? to https://www.example.com/vmi10/

这不会影响任何具有非空查询字符串的 url。

在这里测试:https://htaccess.madewithlove.be?share=34570386-6b48-486b-ba84-32a222921502

您可以将此重定向规则用作主 .htaccess 中的 topmost 规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+[^?]*\?\s
RewriteRule ^ %{REQUEST_URI}? [L,NE,R=301]

# other WP rules below this line