I
I
Ivan2018-09-26 17:51:54
htaccess
Ivan, 2018-09-26 17:51:54

How to make a redirect to a new domain in HTACCESS with the replacement of words in the URL?

initial link (for example)

http://sms.example.com/public/http/?user=andrey&pass=andrey123&action=post_sms&target=71234567890&sender=andrey-win&message=privet

must be brought to
http://s1.example.com/sys/send.php?login=andrey&psw=andrey123&sender=andrey-win&phones=71234567890&mes=privet

change:
user to login
pass to psw
target to phones
message to mes
action=post_sms you can leave
thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-09-26
@dodo512

At the beginning of .htaccess add:

RewriteEngine On

RewriteCond %{HTTP_HOST}    ^sms\.example\.com$
RewriteCond %{QUERY_STRING} ^user=([^&]+)&pass=([^&]+)&action=post_sms&target=([^&]+)&sender=([^&]+)&message=([^&]+)
RewriteRule ^public/http/$  http://s1.example.com/sys/send.php?login=%1&psw=%2&sender=%4&phones=%3&mes=%5 [R=301,L,NE]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question