【问题标题】:htaccess and mod_rewrite using multiple querystringshtaccess 和 mod_rewrite 使用多个查询字符串
【发布时间】:2012-06-25 13:49:18
【问题描述】:

我目前正在使用 htaccess 使用以下方法将单个查询字符串重写为其页面名称,并且工作正常...

 Options +FollowSymLinks


RewriteEngine on
  RewriteBase /

  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ /index.php?page=$1 [QSA]

我的问题是我现在正在尝试在原始查询字符串之上实现其他查询字符串。我可以以/property-listing&property=12-Langworthy-Royston-Grove身份成功访问该页面

但是我希望能够将&property= 重写为正斜杠,因此基本上删除了额外的查询字符串参数,同时在没有传递额外的查询字符串参数的情况下保持正常的重写规则。

感谢您的帮助,

马特。

【问题讨论】:

    标签: .htaccess mod-rewrite query-string


    【解决方案1】:

    尝试在最后添加此规则:

    RewriteRule ^(.+)&property=(.*)$ /index.php?page=$1/$2 [L,QSA]
    

    但是请注意,这仅在 &property= 是 URI 的一部分时才有效(在您展示的示例中),因为它只是 URI 是重写规则的主题,而不是查询字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多