Reputation: 161
I have a quick question. Following problem I have a button on my website that automatically redirects to the German subdomain of the website.
<a href="https://german.hello.com"><img src="images/DE.png">German</a>
An example :
Mainpage: hello.com
Subdomain in the language german: german.hello.com
Now I have all subpages of both languages named exactly the same example :
Mainpage Imprint : hello.com/imprint Subdomain in the language german : german.hello.com/imprint
How can I use a html button to redirect the person to the requested page of the language e.g. he is currently on the contact page how can he only get to german.hello.com/contact through a button ?
My idea the website needs to know where the user is and puts the subdomain german in front of the main domain so he gets the subpage of the selected language.
For this the website needs to know which subpage the user is currently on. In other words, the website must know the URL and simply add the subpage title like contact after the domain german.hello.com/contact. Therefore this must be a variable button.
I was thinking of something like :
<a href="https://german.hello.com{currentpage.php}"><img src="images/DE.png">German</a>
Upvotes: 0
Views: 380
Reputation: 2621
If you want to send the user to the same page under a different subdomain, you can do something like:
<?php
$currentPage = $_SERVER['SCRIPT_NAME'];
$link = "<a href='http://german.hello.com/$currentPage' ><img src='images/DE.png'>German </a>";
?>
Upvotes: 1
Reputation: 23
You could use the relative URLs.
For example, if you are on page hello.com/imprint
and want to come back on the home page, you may want to click on a button with href equals to ..
:
<a href="..">Home</a>
Vice versa, if you are on the home page and want to go on imprint page, you may want to click on a button with href equals to imprint
:
<a href="/imprint">Imprint</a>
Note that with relative URLS you don't care in which subdomain you are: once you are in a specific subdomain, the relative URLS are completed by the browser with the correct one.
Upvotes: 1