.htaccess 301 重定向与重写规则冲突


.htaccess 301 redirect conflicting with rewriterule

我正在尝试重定向URL,但它与重写规则冲突,我正在使用此重定向规则

Redirect 301 /antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs    

它把我带到了这个链接 https://example.com/antique-vintage-rugs/170-antique-rugs?action=clear&template=170-antique-oriental-rugs-carpets 而不是这个 https://example.com/antique-vintage-rugs/170-antique-rugs

我的重写网址是这个

RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^antique-vintage-rugs/(.+) results.php?action=clear&template=$1 [NC]

有什么方法可以获得所需的输出重定向链接吗?

您只需要在此处使用mod_rewrite,而不是将其与mod_alias(Redirect 指令所属的地方)混合使用。当您将两者混合在一起时,两者都最终会处理相同的请求。

因此,与其使用 Redirect ,请使用:

RewriteRule ^antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs [L,R=301]

但请确保它在您的其他规则之前

我遇到了类似的问题。我正在尝试从cpanel添加重定向,而我已经在我的.htaccess文件中编写了一些重写规则。我得到的错误是"没有缓存标签"我最终做的是保留我现有规则的副本并清理 .htaccess。然后去添加我需要的所有重定向 cpanel,然后在最后在文件末尾放回我自己的重写规则。这对我有用