htaccess mod Rewrite Rule - 可选参数

时间:2013-07-09 11:31:51

标签: .htaccess mod-rewrite

我想改写下面的内容:

  1. http://www.mywebsite/address/12345/http://www.mywebsite/address/?param1=12345
  2. http://www.mywebsite/address/12345/12http://www.mywebsite/address/?param1=12345&param2=12
  3. http://www.mywebsite/address/12345/?{otherparam} = 1 to http://www.mywebsite/address/?param1=12345& {otherparam} = 1
  4. 以下是.htaccess文件中的内容。我有前两个工作正常,但我正在努力与第三。我需要第三个传递param1并传递其他可选参数。有人可以帮忙吗?

    RewriteRule ^address/([^/\.]+)/?$ address/?param1=$1  [NC]
    RewriteRule ^address/([^/]+)/([^/\.]+)/?$ address/?param1=$1&param2=$2  [NC]
    

1 个答案:

答案 0 :(得分:2)

您正在寻找QSA标志,该标志会将任何现有查询字符串附加到规则目标中新构建的查询字符串中:

RewriteRule ^address/([^/\.]+)/?$ address/?param1=$1  [NC,QSA,L]
RewriteRule ^address/([^/]+)/([^/\.]+)/?$ address/?param1=$1&param2=$2  [NC,QSA,L]