【问题标题】:Redirect a malformed URL with more than 1 variable重定向具有超过 1 个变量的格式错误的 URL
【发布时间】:2015-12-16 14:51:43
【问题描述】:

使用“malformed double ?”重定向

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

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

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

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

即。

#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

【问题讨论】:

  • 在 php 中执行 print_r($_SERVER['QUERY_STRING']) 以查看您的脚本实际接收的内容。
  • 感谢 hjpotter92 - 不错的工具!

标签: apache .htaccess variables redirect malformed


【解决方案1】:
 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 是否有特定的查询字符串,将其重定向到新位置。

【讨论】:

  • 像魅力一样工作,非常感谢 Starkeen! - 如果你能推荐一个教程,我很乐意得到一个链接。
猜你喜欢
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 1970-01-01
  • 2017-09-08
  • 2019-12-07
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多