Regex Apache配置重定向匹配参数,将一个添加到其他参数
我需要像这样转换url: /fr ca/home.html?titi=toto/fr/home.html?titi=toto&country=ca 当然还有/fr-ca/home.htm/fr/home.html?country=ca 但它总是重定向到主页,删除页面 我错在哪里Regex Apache配置重定向匹配参数,将一个添加到其他参数,regex,apache,Regex,Apache,我需要像这样转换url: /fr ca/home.html?titi=toto/fr/home.html?titi=toto&country=ca 当然还有/fr-ca/home.htm/fr/home.html?country=ca 但它总是重定向到主页,删除页面 我错在哪里 RedirectMatch 301 "^/([a-z]{2})-([a-z]{2})/(.*?)" "/$1/$3?country=$2" RedirectMatch 301 "^/([a-z]{2})-
RedirectMatch 301 "^/([a-z]{2})-([a-z]{2})/(.*?)" "/$1/$3?country=$2"
RedirectMatch 301 "^/([a-z]{2})-([a-z]{2})/(.*)" "/$1/$3&country=$2"
RedirectMatch
指令在这里没有帮助,因为您希望在以前的查询字符串中添加新的查询参数。此功能仅在使用mod_rewrite
模块中的QSA
标志时可用
您可以使用:
RewriteEngine On
RewriteRule ^([a-z]{2})-([a-z]{2})/(.*)$ /$1/$3?country=$2 [L,QSA,NC,R=301]
QSA
(查询字符串附加)标志在添加新查询参数时保留现有查询参数
测试前,请确保清除浏览器缓存