Same WordPress Website but Different Sub Domain for Mobile Version - wordpress

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. It works nicely, but I want to use sub domain m.mydomain.com rather than mydomain.com IF ONLY my website in mobile version. In short, m.mydomain.com and mydomain.com refer to the same website and database, m.mydomain.com address only display for mobile users. 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.

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) :
<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. How to do this can vary depending on which linux distro you are using.
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.
Update: You can use javascript to do the redirect, as long as you know that you are dealing with a mobile client.
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. Sorry about that.

Related

WordPress multisite setup as subdomain - wildcard DNS record setup

I am new to WP multisite environment. I want to setup multisite in my local Ubuntu 14.04 environment. I already have localhost for my main site configured as carbazarlocal.com and its running OK. When I go to Tools > Network Setup I can see two options - Sub-domain and Sub-directory. I want to setup my multisites as sub-domains like dealer1.carbazarlocal.com, dealer2.carbazarlocal.com etc.
On this page WordPress says "You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality". How to do this and where?
In /etc/hosts I have the following entry:
127.0.0.1 carbazarlocal.com
In /etc/apache2/apache2.conf I have the following:
<Directory /var/www/html/carbazar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In /etc/apache2/sites-available/carbazarlocal.com.conf I have this:
<VirtualHost *:80>
ServerAdmin admin#carbazarlocal.com
ServerName carbazarlocal.com
ServerAlias *.carbazarlocal.com
DocumentRoot /var/www/html/carbazar
</VirtualHost>
And in /var/www/html/carbazar/wp-config I have this:
define('WP_ALLOW_MULTISITE', true);
What else I need to do and where to complete the following step:
"You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality"?
If you use Apache server then ...
In the httpd.conf file, or in the include file containing the VirtualHost section for your web account, add a line like this (if it is not already present):
ServerAlias *.example.com
Also create a wildcard DNS record like:
*.example.com A 192.0.43.10
REF https://codex.wordpress.org/Configuring_Wildcard_Subdomains

How to prevent WordPress setup in 'blog' subdomain, redirecting to 'www' when trying to finish Installation

I have a main site http://www.example.com that's written in another language (Ruby/Rails). I want a wordpress blog installed in http://blog.example.com. I have control over the server and DNS.
I have created the necessary CNAME record for the 'blog' subdomain. But after setting up apache and restarting it, when I visit http://blog.example.com, for the final installation steps, I'm redirected to http://www.example.com/wp-admin/install.php.
Also now when I try to visit the main site http://www.example.com, I'm being redirected to the above wordpress install page.
How can I make it work like this: the blog should only reside in blog.example.com path, and the main site should be accessible via http://www.example.com.
Removing the www subdomain is not an option as it's been like that for awhile for the main site. It might be ok, if somehow a redirect can be setup from www to non-www url, though I'm not aware how to set it up.
Please suggest.
Here's the main site's apache conf:
<VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin webmaster#localhost
ServerName http://www.example.com
ServerAlias example.com
DocumentRoot /home/apps/example/current/public
<Directory /home/apps/example/current/public>
AllowOverride all
Options -MultiViews
</Directory>
#RewriteEngine On
#Redirect / http://example.com/
</VirtualHost>
Here's the apache conf for the wordpress under 'blog' subdomain:
<VirtualHost *:80>
ServerName blog.example.com
ServerAlias blog.example.com
ServerAdmin webmaster#localhost
DocumentRoot /home/apps/example_blog/wordpress_blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/apps/example_blog/wordpress_blog>
AllowOverride All
</Directory>
</VirtualHost>
WordPress has domain references in the database and the code which will throw your permalinks off and cause bad redirects. These renegade URLs should appear as 404's on your root domain (example.com). If not I'd double check the root domain with the sub domain removed from the vhosts.
I don't see any issues with your current vhost configuration. I would also try testing the domains in isolation if you suspect its vhost related. I suspect its a WordPress site url issue.
Assuming the database records are incorrect.
Log into phpMyAdmin or other database manager.
Select your WP database.
Go into the wp_options table (wp_ prefix may be different).
Look for the record's with option name = "siteurl" & "home".
Edit these records to reflect your new domain name.
Here's the WordPress documentation on how to switch a sites urls schema.
Document
Your problem is likely deep in various DB references throughout your WP project. I've run into this problem deploying WP before. You'll need to edit the DB directly to fix the issues.
Export your WordPress DB with phpMyAdmin or SequelPro (something that gets you a clean .sql file)
Use a text editor like Sublime or Atom, search for "www.example.com" and replace all with "blog.example.com" then save.
Upload DB to prod location and you should see these errors go away.
This should not happen if your virtual host is configured correctly
but still as your tables are not created so you can only do one try with this step :
you can add in your wp-config.php file the following parameter
define('wp_site_domain', 'blog.example.com');
This will force the wordpress to follow blog.example.com

How to enable wordpress website locally on network and via localhost

My wordpress site works fine on my mac via localhost, using Xammp. I want to view the site on my iPhone. So I type in 192.168.0.2 and voila, it brings up my localhost directory. I then click on the site in question and the content is there but no styling or images. I realise that this is because the paths to all the resources is hardcoded into the wordpress database. So when I am accessing the url via 192.168.0.2/mywebsitename on my iPhone, it's looking for all the resources using a base url of localhost/mywebsitename. Localhost path doesn't exist on my iPhone, only 192.168.0.2 does.
So has anyone found a solution to this little issue? How can I see a wordpress installation by ip address and by localhost access?
For this exact issue, before developing a website. You must create a domain(VirtualHost in apache)
Add the following contents in the file httpd-vhosts.conf, make sure it is included in Apache Configuration. This line ( Include conf/extra/httpd-vhosts.conf ) should be present in httpd.conf
Contents of httpd-vhosts.conf:
NameVirtualHost 192.168.1.26:80
<VirtualHost 192.168.1.26:80>
<Directory "e:/program files/ampps/www/mywebsite">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName 192.168.1.26
ServerAlias 192.168.1.26
ScriptAlias /cgi-bin/ "e:/program files/ampps/www/mywebsite/cgi-bin/"
DocumentRoot "e:/program files/ampps/www/mywebsite"
ErrorLog "E:/Program Files/ampps/apache/logs/192.168.1.26.err"
CustomLog "E:/Program Files/ampps/apache/logs/192.168.1.26.log" combined
</VirtualHost>
(Change the path, ip, etc according to your need). Now after adding the contents. Restart Apache. Now when you access 192.168.1.26 (in my case) from other machine in your network or your same machine. You should see the contents of mywebsite folder directly(or contents index.php if it has any). Now install wordpress using the ip you specified(browser should have that ip in the address bar), in my case 192.168.1.26.
Well I use AMPPS to avoid this headache. It allows me to create domains locally. Also if I have bought a domain say mywebsite.com and i want to add a customized wordpress site on, I create a the domain in the AMPPS with the same name. So the URL of my live website and the local are same. :) Then I simply put the files directly on my server via FTP and obviously import the database on my server.
EDIT: BTW, AMPPS allows to install WordPress in a single click. It has simple interface where you can specify AMPPS to install the WordPress on the created Domain.

Hosting multiple domains in Apache2 - how?

Although I’ve found related articles on stackoverflow, I have seen various suggestions which I’ve tried out but I still experience problems, so that’s the reason why I’m posting this.
I have a question which involves DNS, Debian, Apache2 and Wordpress. I’ve been struggling with this for some time now and haven’t been able to solve it. My current conclusion is that 2there is something with my dns and apache virtual host definitions”, but, as I said I’m far from sure.
This is what my config looks like:
two domains which I “own” hosted by moniker.com - let’s call them domaina and domainb
a hosted vps with Debian, apache2 and wordpress. The vps has ip x.y.z.t
each domain has three ‘A’ records defined: ‘*’, ‘#’ and ‘www’
URL rewrite enabled (a2enmod rewrite)
Wordpress installed and links created to the wordpress directory for both document directories specified in the virtualhost directives below
Both ‘domaina’ and ‘domainb’ point to my vps and this is working ok. However, what I’ve been unable to solve is to have the vps handle “multiple virtual hosts”. I thought I would be able to handle this by using virtual hosts in Apache. For that purpose I’ve defined two sites under /etc/apache2/sites-available which looks like this:
(file: /etc/apache2/sites-available/domaina.com)
<VirtualHost x.y.z.t:80>
ServerName domaina.com
ServerAdmin me#domaina.com
DocumentRoot /var/www/domaina.com
DirectoryIndex index.php
<Directory /var/www/domaina.com/>
AllowOverride all
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
(file: /etc/apache2/sites-available/domainb.com)
<VirtualHost x.y.z.t:80>
ServerName domainb.com
ServerAdmin me#domainab.com
DocumentRoot /var/www/domainb.com
DirectoryIndex index.php
<Directory /var/www/domainb.com/>
AllowOverride all
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Now, when I try to address the sites above from a web-browser I end up at the default apache directory with the index.html file rendered in the browser instead of arriving at the two different wordpress configurations. Obviously there’s something wrong with my thinking around “VirtualHosts” and/or DNS-configurations…
I forgot to mention that I've made loads of /etc/unit.d/apache2 restarts... Sorry...
Frankly speaking I’m lost here and any help on this would be very much appreciated.
Cheers
If you did restart apache and its still not working please respond, as I have experienced similar issues with Apache, especially when getting the virtual host to work. I realise your running on Debian which is different to WAMP, but this is what I do when opening a new virtual host.
First I add the domain to the windows system 32 drivers etc hosts file, it allows for intranet
127.0.0.1 domainname and this stops the url from looking to the web.
Then I have to add the corret directories to the www/your folder.
Just inside the root folder there ought to be a directory called vhosts,
I had to make totaly empty instances of the conf files with just the filename of the virtual hosts inside it so that the changes you made to the httpd-vhosts.conf works.
So what you will need to do is find the wamp/bin/apache/Apache2.2.21/conf/extra/httpd-vhosts makes sure that you have the one from the conf/axtra and not conf/orginal.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/**name of the folder**"
ServerName **as_inserted_in_hosts**
<directory "c:/wamp/www//**name of the folder**">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
Save. Apache stop all services, I also have to restart the service running the intranet in windows to update the changes to the hosts file and then restart apache.
This is what I have to do so that when I open localhost from Apache it allows me to see the links appear under virtual hosts as well as the directories appearing under your projects.
Have a look at this tutorial... Explains how to set up virtual hosts
Do you have a NameVirtualHost directive in your apache2.conf anywhere? You'll need that to enable virtual hosting. It can go in apache2.conf or any file included by apache2.conf. On my server I've got it in ports.conf.
NameVirtualHost *:80
See http://httpd.apache.org/docs/2.2/vhosts/name-based.html#using

Wordpress not working when using Apache virtual hosts

I currently use virtual hosts on my computer so that I can manage multiple sites on my computer.
Currently, I use c:/vhosts/php (default localhost) for regular PHP development, c:/vhosts/BTS for Wordpress, and c:/vhosts/cake for CakePHP development. (see below).
Now when I launch my WAMPP and go to http://BTS, it loads the index page but nothing else loads fine. When trying to click on the links, it links to http://localhost/xxxxx instead of http://BTS/xxxxx. What am I missing here? I don't want the server to access localhost since I'm using localhost for other projects. Please help.
<VirtualHost *:80>
DocumentRoot c:/vhosts/php
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/BTS
ServerName BTS
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/cake
ServerName cake
</VirtualHost>
Go into your MySQL database (thru phpmyadmin or whatever) and look for the following fields
In the wp_options table, change
siteurl
home
To http://BTS instead of localhost.
This will update all your links in wordpress.
You need to tell Wordpress what domain it is sitting on.
Login to your Admin CP, it's in settings somewhere
I think is in wordpress options in settings in general, then change in WordPress Address (URL) and in Site Address (URL), both need to be the same:
This is my configure, but you can change it with BTS
And check if it's right in mysql the configure with
select option_name, option_value from wp_options where option_name = 'siteurl';

Resources