追加查询字符串与htaccess的所有网址

追加查询字符串与htaccess的所有网址

本文介绍了追加查询字符串与htaccess的所有网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关测试的目的,我想追加一个查询字符串(假设测试=真)从我的网站要求的任何URL。

例如。我想改变

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

  • example.com?测试= TRUE
  • example.com/product?测试= TRUE
  • example.com/search?q=string& 测试= TRUE

我尝试这样做:

 重写规则^ /?(。*)http://example.com/$1?testing=true [L,R,NE]
 

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

任何想法?

编辑:

我要补充我正与codeIgniter(PHP)和我目前的.htaccess看起来是这样的:

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上

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

    的RewriteCond $ l ^(指数\ .PHP |公众|图片|机器人\ .TXT | CSS)!
    重写规则^(。*)$的index.php / $ 1 [L]
< / IfModule>
 

解决方案

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

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上

    的RewriteCond%{QUERY_STRING}(^ |&安培)!测试= TRUE(安培; | $)[NC]
    重写规则^%{REQUEST_URI}?测试=真正的[L,QSA,R]

    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    的RewriteCond $ l ^(指数\ .PHP |公众|图片|机器人\ .TXT | CSS)!
    重写规则^(。*)$的index.php / $ 1 [L]
< / IfModule>
 

For testing purposes, I would like to append a query string (let's say testing=true) to any url requested from my website.

E.g. I want to change

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

to

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

I tried this:

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

but it breaks the site. Not an expert.

Any ideas?

EDIT:

I should add I'm working with CodeIgniter (PHP) and my current .htaccess looks like this:

<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>
解决方案

You can use this new rule:

<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>

这篇关于追加查询字符串与htaccess的所有网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:40