我已经在站点周围寻找了答案,并遵循了一些示例,但是我仍然对此没有任何帮助。 我正在尝试重定向以下内容。
www.mydomain.com/?s=flat+roof+specifier+清单 至 www.mydomain.com/resources/flat-roof-checklist /
我的重写规则如下。
RewriteCond %{QUERY_STRING} s=flat+roof+specifier+checklist
RewriteRule ^(.*)$ /resources/flat-roof-checklist/? [L,R=301]
我认为我遇到的问题是“ +”字符。 如果我将URL更改为:
www.mydomain.com/?s=flat%20roof%20specifier%20checklist
和我的重写条件为:
RewriteCond%{QUERY_STRING} s = flat%20roof%20specifier%20checklist
工作正常。
问题在于,URL已经是 www.mydomain.com/?s=flat+roof+specifier+checklist (其中带有+字符),因为该业务已经存在发送了与该特定网址的通信,因此很遗憾,我无法更改它。
我是否缺少某种regx来预先格式化我的网址??
该站点上已经有一个301重定向插件正在运行,但是它也不起作用。 抱歉,我对php,wordpress,htaccess等还很陌生。
任何帮助将不胜感激。
答案 0 :(得分:1)
您可以将模式放入正则表达式捕获组并转义加号,并使用以下命令在我的测试服务器上进行测试
RewriteCond %{QUERY_STRING} (s=flat\+roof\+specifier\+checklist)
RewriteRule ^(.*)$ /resources/flat-roof-checklist/? [L,R=301]