简体   繁体   English

相同的WordPress网站,但移动版本使用不同的子域

[英]Same WordPress Website but Different Sub Domain for Mobile Version

Let say I have WP website on mydomain.com, I'm using WP plugin WP Smart Mobile to automatically convert the website to mobile version depends on the devices. 假设我在mydomain.com上拥有WP网站,我正在使用WP插件WP Smart Mobile来根据设备将网站自动转换为移动版本。 It works nicely, but I want to use sub domain m.mydomain.com rather than mydomain.com IF ONLY my website in mobile version. 它工作得很好,但是我想使用子域m.mydomain.com而不是mydomain.com(如果仅我的网站是移动版本)。 In short, m.mydomain.com and mydomain.com refer to the same website and database, m.mydomain.com address only display for mobile users. 简而言之,m.mydomain.com和mydomain.com指的是同一网站和数据库,m.mydomain.com地址仅显示给移动用户。 Is it possible to do? 有可能吗? If yes, how? 如果是,怎么办?

Thanks for any enlightment for this case. 感谢您对本案的任何启发。

additional information: I'm using linux server with apache web server. 其他信息:我将linux服务器与apache网络服务器一起使用。

The way that I would use it is to create a virtual host for both the domain and the mobile subdomain (the vhost file goes in /etc/apache2/sites-available) : 我使用它的方式是为域和移动子域创建一个虚拟主机(vhost文件位于/ etc / apache2 / sites-available中):

<VirtualHost *:80>
    ServerAdmin root@mydomain.com
    DocumentRoot /var/www/path/to/document/root
    ServerName mydomain.com

   <Directory /var/www/path/to/document/root>
       AllowOverride all # allow overriding of options with .htaccess
   </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin root@mydomain.com
    DocumentRoot /var/www/path/to/document/root
    ServerName m.mydomain.com

   <Directory /var/www/path/to/document/root>
       AllowOverride all # allow overriding of options with .htaccess
   </Directory>
</VirtualHost>

You will then need to enable the virtual host and restart apache. 然后,您将需要启用虚拟主机并重新启动apache。 How to do this can vary depending on which linux distro you are using. 如何执行此操作可能会因所使用的Linux发行版而异。

Once the vhosts are set up, both the domain and the subdomain will point to the same website. 设置虚拟主机后,域和子域都将指向同一网站。 I'm assuming that your wordpress plugin can redirect mobile clients to the subdomain. 我假设您的wordpress插件可以将移动客户端重定向到该子域。

Update: You can use javascript to do the redirect, as long as you know that you are dealing with a mobile client. 更新:只要您知道要与移动客户端打交道,就可以使用javascript进行重定向。

var path = window.location.pathname,
    host = window.location.host,
    mobileVersion = 'http://m.' + host + path;

window.location = mobileVersion;

I also just had a thought, that the virtual host may be entirely unnecessary, as long as there is an A record for your subdomain. 我也只是想过,只要您的子域有A记录,虚拟主机就可能完全没有必要。 Sorry about that. 对于那个很抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM