【问题标题】:Append query string to all URLs with .htaccess使用 .htaccess 将查询字符串附加到所有 URL
【发布时间】:2015-02-02 12:56:30
【问题描述】:

出于测试目的,我想将查询字符串(假设为 testing=true)附加到从我的网站请求的任何 url。

例如我要改变

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

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

我试过这个:

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>

【问题讨论】:

    标签: apache .htaccess codeigniter mod-rewrite url-rewriting


    【解决方案1】:

    你可以使用这个新规则:

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

    【讨论】:

    • 不幸的是,它什么也没做。使用普通 URL 加载页面,不附加查询字符串。
    猜你喜欢
    • 2013-05-27
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多