htaccess 301通过将查询参数添加到URL

时间:2019-02-26 10:08:32

标签: apache .htaccess redirect mod-rewrite

我正在尝试从下面的URL进行301重定向

www.example.com/categories/Writing-Translation

www.example.com/categories/Writing-Translation-jobs

但是,它始终使用以下网址重定向页面

www.example.com/categories/categories/Writing-Translation-jobs?cid=Writing-Translation

这是用于重定向的htaccess代码

301重定向

RewriteCond %{QUERY_STRING} ^cid=Writing-Translation$ [NC]    
RewriteRule ^categories/Writing-Translation$ https://www.example.com/categories/Writing-Translation-jobs [R=301,NE,NC,L]

2 个答案:

答案 0 :(得分:0)

您可以将此规则用作最高规则

RewriteCond %{QUERY_STRING} ^cid=Writing-Translation$ [NC]    
RewriteRule ^categories/Writing-Translation$ /categories/Writing-Translation-jobs? [R=301,NC,L]
目标URI末尾的

?将剥离现有查询字符串。确保在新的浏览器中对其进行测试。

答案 1 :(得分:0)

通过添加“ /?”来使用以下规则。在开始时:

  

RewriteRule   ^ /?categories / Writing-Translation $ https://www.example.com/categories/Writing-Translation-jobs   [L,R = 301]