V
V
VeryLongAgoDid2018-11-27 13:47:14
htaccess
VeryLongAgoDid, 2018-11-27 13:47:14

How to make redirects by UTM tag in .htaccess?

I'm trying to glue duplicates, by UTM tag. Please help
If there is ?SECTION_CODE=..., then make a redirect, but leave everything that comes after the symbol &
?SECTION_CODE=... & ...
Doesn't want to work like that, error 500
RewriteRule ^catalog/([a- zA-Z0-9\-_])/?SECTION_CODE=([a-zA-Z0-9\-_])&(.*)$ /catalog/$1/?$3
The generator produces such a solution. I really don't want to fuss too much

spoiler

# Rewrite --- /catalog/abc/?SECTION_CODE=abc => /catalog/abc/
RewriteCond %{QUERY_STRING} (^|&)SECTION_CODE\=abc($|&)
RewriteRule ^catalog/abc/$ /catalog/abc/?&%{QUERY_STRING}
# Rewrite --- /catalog/abc/?SECTION_CODE=abc&PAGEN_1=2 => /catalog/abc/?PAGEN_1=2
RewriteCond %{QUERY_STRING} (^|&)SECTION_CODE\=abc($|&)
RewriteCond %{QUERY_STRING} (^|&)PAGEN_1\=2($|&)
RewriteRule ^catalog/abc/$ /catalog/abc/?PAGEN_1=2&%{QUERY_STRING}
# Rewrite --- /catalog/abc/?SECTION_CODE=abc&PAGEN_1=3 => /catalog/abc/?PAGEN_1=3
RewriteCond %{QUERY_STRING} (^|&)SECTION_CODE\=abc($|&)
RewriteCond %{QUERY_STRING} (^|&)PAGEN_1\=3($|&)
RewriteRule ^catalog/abc/$ /catalog/abc/?PAGEN_1=3&%{QUERY_STRING}
# Rewrite --- /catalog/abc/?SECTION_CODE=abc&PAGEN_1=99 => /catalog/abc/?PAGEN_1=99
RewriteCond %{QUERY_STRING} (^|&)SECTION_CODE\=abc($|&)
RewriteCond %{QUERY_STRING} (^|&)PAGEN_1\=99($|&)
RewriteRule ^catalog/abc/$ /catalog/abc/?PAGEN_1=99&%{QUERY_STRING}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-11-28
@VeryLongAgoDid

RewriteCond &%{QUERY_STRING} ^(.*?)&SECTION_CODE=[^&]*(.*)
RewriteCond %1%2             ^&*(.*)
RewriteRule ^catalog/.+/$ /$0?%1 [R=301,L]

V
Viktor Taran, 2018-11-27
@shambler81

GET - is not part of the url and it does not get into the rewrite rule at all
https://www.generateit.net/mod-rewrite/index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question