I
I
IgorRastarov2018-03-24 15:58:27
PHP
IgorRastarov, 2018-03-24 15:58:27

How to go to a subdomain without changing the current page?

Guys, hello everyone. I am writing here to you, because I don’t even know how to correctly google my question.
I have a site test.ru And a subdomain moscow.test.ru
They have the same directory.
I have a button - switch subdomains. Accordingly , test.ru and moscow.test.ru The
question is how to implement such a logic of switching to a subdomain so that if I am on the page
test.ru/information/law/
When I click on the button to go to the subdomain, I do not go to the main one - but remain on / information/law/
I was thinking of doing this:

$poddomen = $_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]

And this variable into a link to the subdomain. But the problem is that SCRIPT_NAME is /information/law/index.php and writing a rule in .htaccess to remove index.php does not help.
Please let me know if there is a suitable solution. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tolmachev, 2018-03-24
@dark_tke

Your question has several solutions.
The most obvious:
1. Make a redirect to the address of the page you need when you click on the button. This can be done on the javascript side, but if you need a solution, php parse_url () will help you.
2. Store the value of the desired page in a session variable.
3. Change the address of the page using javascript through the history api, in fact, without leaving it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question