2014-12-04 37 views
1

为了测试的目的,我想追加一个查询字符串(比如说testing = true)到我的网站请求的任何网址。将查询字符串附加到所有使用.htaccess的网址

E.g.我想改变

  • example.com
  • example.com/product
  • example.com/search?q=string

  • example.com? testing = true
  • example.com/product? 测试=真
  • example.com/search?q=string & 测试=真

我尝试这样做:

RewriteRule ^/?(.*) http://example.com/$1?testing=true [L,R,NE] 

,但它打破了现场。不是专家。

任何想法?

编辑:

我要补充,我使用CodeIgniter(PHP)和我目前的.htaccess的工作是这样的:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

回答

4

你可以使用这个新的规则:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{QUERY_STRING} !(^|&)testing=true(&|$) [NC] 
    RewriteRule^%{REQUEST_URI}?testing=true [L,QSA,R] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 
+0

不幸的是,它什么都没做。页面使用正常的URL加载,查询字符串不会被追加。 – lesssugar 2014-12-04 15:36:16

+0

现在用'R'标志尝试更新的代码。 – anubhava 2014-12-04 15:36:54

+1

工程像魅力! – lesssugar 2014-12-04 15:38:18

相关问题