.htaccess 重定向已重定向的页面

.htaccess 重定向已重定向的页面,.htaccess,mod-rewrite,url-rewriting,url-routing,.htaccess,Mod Rewrite,Url Rewriting,Url Routing,情况是这样的。我们已经重写了这些URL,但我们希望更改这些页面的格式,使它们用连字符而不是斜杠分隔 我尝试了redirectmatch,但这在URL的末尾添加了额外的php值参数。结果是 RewriteRule ^teamstore/(.*)/$ /teamproduct.php?teamproduct=$1&products=true [NC,L] RewriteRule ^teamstore-(.*)/$ /teamproduct.php?teamproduct=$1&pro

情况是这样的。我们已经重写了这些URL,但我们希望更改这些页面的格式,使它们用连字符而不是斜杠分隔

我尝试了redirectmatch,但这在URL的末尾添加了额外的php值参数。结果是

RewriteRule ^teamstore/(.*)/$ /teamproduct.php?teamproduct=$1&products=true [NC,L]
RewriteRule ^teamstore-(.*)/$ /teamproduct.php?teamproduct=$1&products=true [NC,L]
结果是

RedirectMatch 301 /teamstore/(.*) http://www.domainname.com/teamstore-$1/
我希望键入原始地址teamstore/info/的人直接转到teamstore info/-有什么想法可以实现这一点吗


主要原因是为了避免谷歌搜索结果中现有链接的重复内容问题

规则的顺序可能很重要,但是如果您出于SEO原因想要301重定向初始请求,那么我会将您的重接线更改为以下内容

teamstore-valuehere//?teamproduct=2352323&productes=true
这将首先将
teamstore/info/
转换为
teamstore info/
,并发送相应的301响应。第二次通过时,它将重定向到您想要的php


注意,就性能而言,这并不理想。然而,它确实实现了让谷歌快乐的目标。

这并不是重定向最初的重定向。它显示teamstore/而不显示任何重定向或任何php数据。我正在使用wordpress,所以这可能是一些后端问题的结果,我现在要仔细检查一下,但我不认为有什么不合适的地方。-我需要重新启动apache吗?我的假设是否定的,因为已经做了更改,但它们不是预期的更改,哈哈。我更新了代码,再试一次。然而,WordPress有自己的重写规则。您可能需要使用它们。谢谢-我们开发了一个自定义插件,这样我们就不会使用WordPress规则,但是.htaccess文件,我将试一试。再次感谢!当我添加另一个斜杠时-我成功了-RewriteRule^teamstore/(.*)/$teamstore-$1/[R=301,L]RewriteRule^teamstore-(.*)/$/teamproduct.php?teamproduct=$1&products=true[NC,L]对不起,是的,您的尾部斜杠是必需的,我没有放回去。我已经更新了我的答案。谢谢
RewriteRule ^teamstore/(.*)/$ teamstore-$1/ [R=301,L]
RewriteRule ^teamstore-(.*)/$ /teamproduct.php?teamproduct=$1&products=true [NC,L]