0

使用“畸形双?”重定向

我尝试以下操作:必须保持活动的旧 URL 形成如下:/index.php?id=5041?var1=val1&var2=val2&var3=val3

我必须把它重定向到这样的东西:

/path1/path2/?id=1234?var1=val1&var2=val2&var3=val3

无论我尝试什么 - 它要么是 index.php 中的无限循环,要么是在 id 之后切断其余的 var。其余的字符串应该简单地连接。

IE。

#Only if id = 1234
RewriteCond %{QUERY_STRING} ^id=1234? [NC]
#get id for variable $1
RewriteCond %{QUERY_STRING} id=(\d+) [NC]
#get rest for variable $2
RewriteCond %{QUERY_STRING} val1=(\d+) [NC]
RewriteRule ^index\.php$ /path1/path2/?myid=%1&val2=%2
4

1 回答 1

0
 RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.php\?id=([^?]+)\?var=([^&]+)&var2=([^&]+)&var3=([^\s]+) [NC]
RewriteRule ^index\.php$ /path1/path2/ [QSA,NC,L,R]

以上条件

RewriteCond %{THE_REQUEST} /id=([^?]+)\?var=([^&]+)&var2=([^&]+)&var3=([^\s]+) [NC

检查 /index.php 是否有特定的查询字符串,将其重定向到新位置。

于 2015-12-16T06:44:35.147 回答