【问题标题】:Apache redirectMatch, add query stringApache redirectMatch,添加查询字符串
【发布时间】:2021-05-15 07:00:27
【问题描述】:

我正在从子文件夹重定向到子域。这工作正常,但我想在我的网址末尾附加一个查询字符串来跟踪有多少人被重定向。

RewriteRule ^/my-folder/(.*)$ https://subdomain.example.com/?ref=my_ref [R=302,L]

根据this article,以上内容应该可以工作,但事实并非如此。

它只是将我重定向到https://subdomain.example.com/

如何在重定向期间添加?ref=my_ref

编辑: 完整的 .htaccess

#to remove old /forum/topic and keep /topic
RewriteRule ^forum/topic/(.*)$ /topic/$1 [L,NC,R=301]

### Rewrites Engine
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]

RewriteRule ^/my-folder/(.*)/?$ https://subdomain.example.com/?ref=$1 [R=302,L,NC]      

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite friendly-url


    【解决方案1】:

    您是否可以使用您展示的示例尝试以下操作。我希望你正在寻找这个。请在测试您的 URL 之前清除您的浏览器缓存。

    ### Rewrites Engine
    <IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^my-folder/(.*)/?$ https://subdomain.example.com/?ref=your_string [R=302,L,NC]      
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2012-08-06
      • 2012-09-21
      • 2022-01-22
      • 2021-06-28
      • 2023-03-22
      • 1970-01-01
      • 2021-02-17
      • 2014-07-27
      • 1970-01-01
      相关资源
      最近更新 更多