Php .htaccess 301重定向与重写规则冲突
我正在尝试重定向URL,但它与重写规则冲突,我正在使用此重定向规则Php .htaccess 301重定向与重写规则冲突,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我正在尝试重定向URL,但它与重写规则冲突,我正在使用此重定向规则 Redirect 301 /antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs 它把我带到了这个链接 而不是这个 我的重写URL是这样的 RewriteCond %{QUERY_STRING} (.*) RewriteRule ^antique-
Redirect 301 /antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs
它把我带到了这个链接
而不是这个
我的重写URL是这样的
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^antique-vintage-rugs/(.+) results.php?action=clear&template=$1 [NC]
有什么方法可以获得所需的输出重定向链接吗?您只需要在此处使用mod_rewrite,而不需要将其与mod_别名(在
重定向
指令所属的位置)混合使用。当您将两者混合使用时,两者最终都会处理相同的请求
因此,不要使用重定向
,而是使用:
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获得的所有重定向,最后在文件末尾放回我自己的重写规则。这对我很有用