lpetrucci
lpetrucci

Reputation: 1679

Apache redirectMatch, add query string

I'm redirecting from a subfolder to a subdomain. This is working fine, but I'd like to append a query string at the end of my url to track how many people have been redirected.

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

The above should be working according to this article, but it doesn't.

It just redirects me to https://subdomain.example.com/

How do I add ?ref=my_ref during a redirect?

Edit: The full .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>

Upvotes: 1

Views: 177

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

With your shown samples could you please try following. I hope you are looking for this one. Please clear your browser cache before testing your URLs.

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

Upvotes: 3

Related Questions