D
D
Dmitry2016-06-15 21:43:04
Apache HTTP Server
Dmitry, 2016-06-15 21:43:04

How to redirect requests from one site to another with substitution?

Hello dear!
There is a very popular site site.ru. The URLs of his pages look like:

  • site.ru
  • en.site.ru
  • ru.site.ru/product/1

etc. But, as a rule, the address to a specific page is very long, so I created a link shortener for it. Let's call it so.kr
Now I got the idea to make it even easier for users to create short links by simply substituting a letter for site.ru - I registered the domain osite.ru and I want each request to look like:
  • site.ru
  • en.osite.ru
  • ru.osite.ru/product/1

redirected accordingly to:
  • so.kr/index.php?url=site.ru _
  • so.kr/index.php?url= en.site.ru
  • so.kr/index.php?url=ru.site.ru/product/1 _

That is, along with subdomains, of which there are a lot, and new ones may appear. Well, and, accordingly, with substitution as a variable in the URL.
But when you go to so.kr/index.php?url=ru.site.ru/product/1, my shortener immediately creates a short link itself.
How to implement such a redirect?
(I have Ubuntu/Apache/PHP)
Thanks in advance for any hints!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-06-21
@seventh

I don't fully understand it myself, but it seems to work:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^([\w\d]+)\.osite\.ru$
RewriteRule ^(.*)$ http://so.kr/index.php?url=http://%1.site.ru$1 [NC,L,QSA]

S
Sergey, 2016-06-16
@hamnsk

I added these lines to the apache vhost.
ProxyPreserveHost On
ProxyRequests Off
ProxyVia full
ProxyPass what_requested where_to_send
ProxyPassReverse what_requested where_to_send
But I had 1 way, I think the meaning is the same, just get excited with variables...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question