2011-11-12 21 views
0

我正在寻找的是从动态URL中剥离查询参数,该参数也需要使用HTACCESS进行清理。使用htaccess去除或重写已清理网址的查询字符串

  1. 该网址首先以http://testdomain.com/post.php?id=3326开头。

  2. url被重写为http://testdomain.com/post/3326/

  3. 有些链接得到“?REF = no_set” 追加到结尾

  4. 地址现在需要从http://testdomain.com/post/3326/?ref=no_set重定向到http://testdomain.com/post/3326/

在某些情况下我需要添加一个新的查询参数“?ref = no_set”到网址,但我想知道是否有可能剥离该查询参数,并仍然能够使用$ _GET在PHP中检索它,即使它没有被重写。

任何帮助,将不胜感激!

回答

0
RewriteEngine on 

RewriteCond [conditional reg ex here] 

RewriteRule [rewrite reg ex here] - [CO=ref:no_set:.testdomain.com] 
+0

我现在使用的RewriteRule是:RewriteRule^post /([0-9] {1,11})/ $ post.php?id = $ 1&ref = no_set [L,QSA]。 我可以从它剥离查询参数:RewriteCond%{QUERY_STRING} ref = RewriteRule(。*)http://testdomain.com/$1? [R],但是我这样做时无法使用$ _GET ... – stwhite

0

简单...

RewriteEngine on 
RewriteCond %{QUERY_STRING} !^$ 
RewriteRule .* http://testdomain.com%{REQUEST_URI}? [R=301,L] 
# ADD CODE TO HANDLE YOUR REWRITES AFTER THIS 

有一个愉快的一天! ;)