How to make?

Hello!
There is a challenge when switching to a subdomain m.site.com (or www.m.site.com)
the user to give the mobile version of the site.
Here is the code
if ($_SERVER["HTTP_HOST"] == 'm.site.com' || $_SERVER["HTTP_HOST"] =='www.m.site.com'){
$styleid = 6; // this part is responsible for displaying the simplified view, i.e. the mobile
$userselect = true;
}

This forum is Vbulletin, appropriate changes in its code made - not only triggered the code above.
The idea of what - if one day site.com he is shown the full version of the site
If entering one of the subdomains then the machine should activate mobile view

The problem is that the redirect is showing but the mobile version is not happening. Everything goes through https, maybe here the problem?

Nginx redirect code
server {
 server_name m.site.com www.m.site.com;
return 301 https://site.com;
April 7th 20 at 10:53
3 answers
April 7th 20 at 10:55
Solution
In General, the method of a crutch was able to get to work this way

server {
server_name m.site.com www.m.site.com;
return 301 https://site.com/index.php?styleid=6;

That is the last line opens the forum in a mobile version. If you keep repeating please specify what number is your mobile style, this in my case 6 - if you have another figure of her and the substitute.
Works like a AK74.

PS there is a nuance - perhaps open another site if you sit on one IP multiple websites, here is a question not in this subject....
April 7th 20 at 10:57
1. According to said
return 301 https://site.com/index.php?styleid=6;
That is the last line opens the forum in a mobile version.

you have turned register_globals=On, so when entering the url https://site.com/index.php?styleid=6; automatically set the variable $styleid = 6;. But if you go to https://site.com/index.php?styleid=3 - it is established in 3 - check!

If so, not only are you in danger, you still works all on the verge of a foul. If hoster will turn off register_globals or switch to PHP >= 5.4.0 - you will turn off the mobile version.

In the search results the mobile version of the site, you will not m.site.comand site.com?styleid=6, that is not good.



2. If you have mobile and desktop vesriya website are processed by the same engine, config virtual host should be:
server {
 server_name site.com www.site.com m.site.com www.m.site.com;
}

that is, all domains have to register one virtual host. Then you will have a corresponding $_SERVER['HTTP_HOST']:
site.com - if you go to site.com
www.site.com - if you go to www.site.com
m.site.com - if you go to m.site.com
www.m.site.com - if you go to www.m.site.com

Now config your virtual hosts just redirects m.site.com on site.comthat is to go to the mobile version simply impossible.



3. I would not trust $_SERVER['HTTP_HOST'] - sends it to the user that is fraught with problems and can be unsafe.
I always rely on $_SERVER['SERVER_NAME'], but that it always correctly showed the domain/subdomains - in site config for Apache it is necessary to register UseCanonicalName On. What is prescribed for the nginx server - I don't know, maybe he and so displays it correctly.

UPD: I got excited. Here it is necessary to use $_SERVER['HTTP_HOST'] because $_SERVER['SERVER_NAME'] will depend on the settings of the web server, and may not show m.site.comif he is hanged by the alias...
Thank you for the detailed answer!

1. A function exhibited in Off - everything works. Version Php7.2, Nginx, Php7.2-fmp

2. Config web server mob version generally placed in a separate file and its work is purely on a redirect in it and prescribed only
server {
 server_name m.site.com www.m.site.com;
}


3. The third option for the sake of which all and was started - does not work, unfortunately, so I had
mount the crutch in the form of a redirect with a direct indication of the style
so this design is generally removed from the code of the forum
if ($_SERVER["HTTP_HOST"] == 'm.site.com' || $_SERVER["HTTP_HOST"] =='www.m.site.com'){
$styleid = 6; // this part is responsible for displaying the simplified view, i.e. the mobile
$userselect = true;
}
- Stephanie.Aufderhar28 commented on April 7th 20 at 11:00
@Stephanie.Aufderhar28maybe the Vbulletin engine emulates register_globals, because you are triggered automatically GET variables from parameters.

Why do not you want to make m.site.com www.m.site.com in the configuration of the server, where you specify the server_name site.com www.site.com; ?
Then code:
if ($_SERVER["HTTP_HOST"] == 'm.site.com' || $_SERVER["HTTP_HOST"] =='www.m.site.com') {
 $styleid = 6; // this part is responsible for displaying mobile view
 $userselect = true;
 }
must earn. And the mobile version will have the url m.site.comthat is correct from the point of view of usability and SEO. - Jewell.Labadie66 commented on April 7th 20 at 11:03
@Jewell.Labadie66, it is included in one of the many files of vbulletin forum and not in the config servers.
If the above design worked in the forum I wouldn't even bother with the server itself..
The source which makes the link https://legnum.info/mobilnaya-versiya-vbulletin-3-... - Stephanie.Aufderhar28 commented on April 7th 20 at 11:06
@Stephanie.Aufderhar28, according to your link:
create domain type m.vashsayt.com website and add it to the alias domain

Adding an alias domain in your virtual host configuration nginx has nothing to do with the engine files forum Vbulletin, and does not affect them.
Just aliases m.site.ru www.m.site.ru it was necessary to add to the existing config to a string server_name site.ru www.site.ru;.
For example, www.site.ru you there, and added an alias (alias) to main domain site.ru.

If you are satisfied - let it work as it is, the more the topic is beyond the scope of the issue raised.



PS: If anyone is interested what will used by Michael "spike method" - welcome under the spoiler:
spoiler
Just keep in mind that neither Yandex, nor Google in this case will not be able to determine the availability of the mobile version of the website. For example, recommendations from Yandex:
If the mobile version of the site located in a subdirectory of the main site, indexing Yandex robot will not be able to index the data and to recognize the website mobilephone. Use responsive design or dynamic layout.


Plus, with the resulting system you have the url, you will have a hard time to specify:
<link rel="alternate" href="http://m.example.com/page-1">

on the pages for the desktop and
<link rel="canonical" href="http://www.example.com/page-1">

on the pages for mobile devices.

Therefore, from the point of view of PS, you will have a bunch of duplicate pages, which they eventually stick together, but "lightweight" version of the forum. It will remain in the search engine results.

And if you change the template for the mobile version, it will be you under another ?styleid=##, so are guaranteed to get more duplicates of pages, and the loss of external references that point to non-existing page with the old ?styleid=6
- Jewell.Labadie66 commented on April 7th 20 at 11:09
@Jewell.Labadie66, of course I tried initially to put the alias in the nginx configuration-a from the primary domain which is spinning forum. But he has not earned.
On one white IP hanging a dozen sites - so what is the problem with ssl certificates, I thought sod it and figs with it, works fine.
With regards to the SEO changes with search engines, and TP in this case is absolutely not critical, and the forum have been beaten, his theme even 10-12 years ago it worked, just kill the creators of the hand does not rise on this he just lives like an old man in a nursing home :)
There is in the community of the past is left dead 100 uniques a day.....
In any case, thank you for taking my time! - Stephanie.Aufderhar28 commented on April 7th 20 at 11:12
@Stephanie.Aufderhar28,
what a jamb with ssl certificates

Most likely, subdomains m.site.com and www.m.site.com not included in the ssl certificate.

If you have console access to UNIX, give command:
true | openssl s_client -showcerts -connect habrahabr.ru:443 2>&1 | openssl x509 -text | grep -o 'DNS:[^,]*' | cut-f2-d:

only instead habrahabr.ru specify your domain.

You can check using an external SSL checkers, for example, through https://2ip.ru/ssl-info/

If there is no certificate with a wildcard name of the species *.site.comand only domains site.com and www.site.com - ssl-certificate need to be re-done to include subdomains m.site.com and www.m.site.com. Or do wilcard-certificate *.site.com on all subdomains. - Jewell.Labadie66 commented on April 7th 20 at 11:15
@Jewell.Labadie66, the team led all the sites in the column, I don't know how come on every site and its www has genericos separately.... - Stephanie.Aufderhar28 commented on April 7th 20 at 11:18
@Jewell.Labadie66, Alternative addresses (SAN) , is a delusion... as it is now, each website to make it a personal certificate and not a bunch? - Stephanie.Aufderhar28 commented on April 7th 20 at 11:21
@Stephanie.Aufderhar28why, I've done a bunch to all sites. For example, Let's Encrypt allows you to have up to 100 websites/domains in one certificate. And supports wildcard certificates. So I generates certificates for 50 domains (the other 50 is taken under *.domain) - Jewell.Labadie66 commented on April 7th 20 at 11:24
@Jewell.Labadie66, Oh how, did not think that so possible (well, can you?)
as for each domain to generate your certificate? - Stephanie.Aufderhar28 commented on April 7th 20 at 11:27
It depends on what CA you take the certificates. I take in the Let's Encrypt, a free DV(ownership of the domain) for 3 months. Hosting installed certbot, which itself extends them via the cron.

One certificate for a bunch of domains, it is convenient when a lot of sites in the config file of the web server registers the same certificate, not 50 different.

DNS-server I have on cloudflare for a domain sortboth the indicated key to access the cloudflare(cloudflare is in the file.ini), and he affirms the right to the domain using a DNS record (wilcard certificates *.site.com can only be obtained through a dns record).
Generated certificates(at least one domain, at least 100) with the command:
certbot certonly \
 -a dns-cloudflare \
 --dns-cloudflare-credentials /usr/local/etc/apache22/ssl/cloudflare.ini \
 --dns-cloudflare-propagation-seconds 30 \
 -d domain.ru \
 -d *.domain.ru

there you can specify up to 100 domains. The name of the folder with the certificate for the first domain in the list.
All sertbot puts the keys of a certificate in a specific folder that I specify in the config file of the web server. The extended certificate will be there under the same name.

How and through whom receive SSL certificates you I don't know. But most likely automatically through your hosting company.

PS: For ssl certificates correct to make a separate topic, not offtopic. And then tell for your specific case. - Jewell.Labadie66 commented on April 7th 20 at 11:30
@Jewell.Labadie66, me too it Let's Encrypt, mainly domainname and www.имядомена -wildcard is not needed
OK, thanks for the answers! - Stephanie.Aufderhar28 commented on April 7th 20 at 11:33
basically a domainname and www.имядомена
add back m.domainname www.m.имядомена and they will be added to the already issued certificate:
certbot --expand-d domain.com,www.domain.com,m.domain.com,www.m.domain.com

The first two domains domain.com,www.domain.com exactly in the same order as you specified in the certificate (otherwise you can change the name of the folder with the certificate). The other new subdomains are added at the end.

The --expand adds a new domain to the existing certificate. I'm sometimes prompted to enter a list of domains by hand - type:
domain.com,www.domain.com,m.domain.com,www.m.domain.com
and everything should be okay! - Jewell.Labadie66 commented on April 7th 20 at 11:36
@Jewell.Labadie66, Yes, it is true, only I don't like the mess, why would you do that?
If I accidentally saw myself and you confirmed my words, I'd be beating my head against the wall trying to find a solution... - Stephanie.Aufderhar28 commented on April 7th 20 at 11:39
@Stephanie.Aufderhar28, nicho not understand about the "mishmash". Here's the debriefing:

You have added a new subdomain for mobile version - http:// you all should start immediately.
Https:// logically, we had to make a new subdomain SSL certificate. You figured it out, judging by the phrase:
what a jamb with ssl certificates, I thought sod it and figs with it, works fine.


Instead of the certificate extension (which would have taken 2 minutes), you made a patch, redirect removing subdomains for mobile site version.

I don't understand how you have a redirect from https:// m.site.com on return 301 https:// site.com/index.php?styleid=6;as https://m.site.com/ without an ssl certificate must be available. But with http:// m.site.com/ redirect should work.

Still, you have a "mishmash" was originally, or became? :) - Jewell.Labadie66 commented on April 7th 20 at 11:42
No, the hash in this case, the certificate data for all my sites - Habr did not do....
Yes, all domains received a certificate and M and the BBB, etc
Here was an ambush:
But with http:// m.site.com/ redirect should work.

until the mobile domain has not been generated, the user output crasnoe a warning that the site certificate which is a redirect has a certificate from another - randomly substituted any of those that were in the same sertifikaat on all domains, probably wrong again described everything :)
But it was something like this - but after generating all the domains in your certificate SSL everything fell within the norm - and most importantly, all sites need to wrap it with 80 port to 443 in the config - Stephanie.Aufderhar28 commented on April 7th 20 at 11:45
April 7th 20 at 10:59
Check out:
var_dump($_SERVER['HTTP_HOST']);
exit;

Find more questions by tags PHPvBulletinWeb Development