不正确的 htaccess 重写规则

Incorrect htaccess rewrite rule

我正在使用以下代码,但显示不正确。

错误:目前域名前面多了一个"/",后面多了一个"[QSA,L]"域名。 希望现在有人可以帮助我。

add_action( 'init', 'mdv_add_rule' );
function mdv_add_rule() {
    add_rewrite_rule( 'demo/(.+)$', 'https://example.com/ [R=301,L]' );
}

谢谢观看

I need to do it this way in the main htaccess section to avoid the case when using the "options-permalink" setting they will be removed.

为避免在 WordPress 中重置永久链接时指令为 removed/overwritten,您只需将指令添加到 .htaccess 文件的顶部, # BEGIN WordPress节。

无论如何,任何外部重定向都应该在任何 WordPress 重写之前进行(包括在 RewriteRule ^index\.php$ - [L] 指令之前)。

您不需要重复 RewriteEngine On 指令,因为它已经包含在文件后面出现的 WordPress 部分中。 (如果您有多个 RewriteEngine 指令,那么 last 实例将获胜并控制整个文件。)