A
A
Alexey Dzyuba2018-04-24 15:47:21
htaccess
Alexey Dzyuba, 2018-04-24 15:47:21

How to set rewrite rule only for GET parameter (query string)?

Hello. There is a site . There is a url (

http://stopgo.by/audi/a6313/a6c64f2004-2011718?attr_id=58
). The GET parameter serves as a filter here (this is the part ID).
The fact is that this parameter is also used in other URLs, for example here ( http://stopgo.by/catalogs?attr_id=70).
I would like to make it so that only this GET parameter changes, I probably want to replace it with part-id=42, that is, so that, for example, http://stopgo.by/catalogs/part-id=42or
http://stopgo.by/audi/a6313/a6c64f2004-2011718/part-id=42
.
That is, as I understand it, you need to make sure that this parameter is at the very end of the url. How it is possible to register it in RewriteRule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-04-24
@shambler81

you want to change only the get parameter itself?
# 301 --- stopgo.by/audi/a6313/a6c64f2004-2011718?attr_id=58 => stopgo.by/audi/a6313/a6c64f2004-2011718?attr_id=58

RewriteCond %{QUERY_STRING} (^|&)attr_id\=([0-9]{1,})($|&)
# если есть такой гет параметр
RewriteRule ^(.+)$ /$1\?part_id=%2 [L,R=301]
#То выделить все что есть в урле и прихреначить к нему такой гет параметр

Where
(.+) - one or more characters and since this is the first bracket in the steering wheel (and there are no parameters in it) then This$1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question