A
A
aliasst2021-10-14 20:58:08
htaccess
aliasst, 2021-10-14 20:58:08

How to redirect encoded url via htaccess?

There is an encoded URL where all special characters are replaced by a percent sign with a number :
site.ru/%3Fs%3Dsanivite%26post_type%3Dproduct%26type_aws%3Dtrue?_openstat=dGVzdDsxOzE7

special characters)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-10-14
@aliasst

RewriteEngine on

RewriteCond %{THE_REQUEST} ^\S+\s/%3F [NC]
RewriteRule .* /$0 [R=301,L,QSA]

The %{THE_REQUEST} variable stores the original query string in its entirety:
GET /%3Fs%3Dsanivite%26post_type%3Dproduct%26type_aws%3Dtrue?_openstat=dGVzdDsxOzE7 HTTP/1.1

The template ^\S+\s/%3Fcatches all addresses starting with /%3F
The input of the RewriteRule is a string after decoding the sequences %XX
?s=sanivite&post_type=product&type_aws=true
The QSA flag allows you not to lose _openstat=dGVzdDsxOzE7 and as a result the redirect will be to the address:
/?s=sanivite&post_type=product&type_aws=true&_openstat=dGVzdDsxOzE7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question