【问题标题】:ReWrite rule for long URL长 URL 的重写规则
【发布时间】:2014-10-21 12:02:30
【问题描述】:

我正在关注重写规则广告

RewriteEngine On
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteRule ^(.*)/(.*)/?$ index.php?rt=$1/$2  [L]
RewriteRule ^(.*)/(.*)/(.*)/?$ index.php?rt=$1/$2/$3  [L]

如果 URL 像 http://www.example.com/manage/ne/new?query=123 means 一样,我将继续使用 php 中的“$_GET”获取在 url 中传递的“查询”的值。

它像`http://www.example.com/index.php?rt=manage/ne/new一样重定向

但我需要的是http://www.example.com/index.php?rt=manage/ne/new&query=123

谁能帮我解决这个关于 Htacces 的问题。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    底部 2 条规则中需要 QSA 标志:

    RewriteRule ^([^/]+)/(.+)/?$ index.php?rt=$1/$2  [L,QSA]
    RewriteRule ^([^/]+)/([^/]+)/(.+)/?$ index.php?rt=$1/$2/$3  [L,QSA]
    

    QSA(查询字符串附加)标志在添加新参数时保留现有查询参数。

    【讨论】:

      猜你喜欢
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      相关资源
      最近更新 更多