Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Apache配置重定向匹配参数,将一个添加到其他参数_Regex_Apache - Fatal编程技术网

Regex Apache配置重定向匹配参数,将一个添加到其他参数

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})-

我需要像这样转换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})-([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
(查询字符串附加)标志在添加新查询参数时保留现有查询参数

测试前,请确保清除浏览器缓存