Have subdomain act as root (htaccess?) - wordpress

I have a website, with some content in the root folder.
I then have a Wordpress site in a subfolder of a subdomain. So for example the url to the Wordpress 'contact' page looks like this.
subdomain.mywebsite.com/subfolder/contact/
Is there a way to get this Wordpress site to act as the root of the website without moving files around? Either through an htaccess file or any other method?
It would be important that the user doesn't know they are in a subdomain/subfolder, so for the contact page of the wordpress site the url bar would have to look something like:
www.mywebsite.com/contact/
Would really appreciate any help.

You can do that in the vhost entry of your webserver.
Example main entry:
<VirtualHost *:80>
ServerAdmin xxx#xxx.com
DocumentRoot "c:/Users/xxx/Documents/www/"
ServerName xxx.com
ErrorLog "logs/xxx.error.log"
CustomLog "logs/xxx.access.log" common
</VirtualHost>
Example subdomain entry:
<VirtualHost *:80>
ServerAdmin xxx#xxx.com
DocumentRoot "c:/Users/xxx/Documents/www/subfolder"
ServerName subdomain.xxx.com
ErrorLog "logs/subdomain.xxx.error.log"
CustomLog "logs/subdomain.xxx.access.log" common
</VirtualHost>

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -f
RewriteRule ^([^/]+)/?$ /subfolder/$1 [L]
This will internally map /file/ to /subfolder/file if the requested file exists in /subfolder.

Related

Rewrite rules all variants of one main domain to another

Say I'd like all traffic from one web domain to be redirected to another. Both sites are Wordpress sites. What's the best way to do this? By including rewrite rules in .htaccess?
For example -
domain1.com/(anything) --> domain2.com
subdomain.domain1.com/(anything) --> domain2.com
If .htaccess, can someone give me some pointers as to what the rule might look like?
Thanks.
You can do this with a RewriteRule. You want to put this inside a VirtualHost block. Example:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName domain1.com
ServerAlias *.domain1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteRule ^(.*)$ http://domain2.com$1 [R]
</VirtualHost>
This will take anything to the right of domain1.com and any subdomain of domain1.com and issue a 301 redirect to http://domain2.com/what/ever/path/was/requested

Configuring .htaccess for multiple wordpress sites

I have multiple wordpress installs that I need to access with multiple domains and I need a way to accomplish this. I have devised a folder structure that I think will be the best way, but I need help with the .htaccess. For simplicity sake, let's say I have two wordpress sites. Fully separate.
www.b.campscoreboard.net is in the folder
/a/b
www.c.campscoreboard.net is in the folder
/a/c
www.campscoreboard.net is pointing to
/a
The a folder contains nothing except an .htaccess file to help me route the domains properly. That's where I need help. I would like to point www.campscoreboard.net to that root /a folder. In my perfect world, the following things would work.
The "b" site would work just fine using www.b.campscoreboard.net or campscoreboard.net/b
The "c" site would work just fine using www.c.campscoreboard.net or www.campscoreboard.net/c
I need "b" and "c" to have their built in permalinks functions to still work. In other words, if I type www.c.campscoreboard.net/forums, I need that to work. I don't want to have to go all the way back to www..campscoreboard.net/c/forums for my links to work (which is what it's currently doing).
What needs to be in that .htaccess file in the /afolder to properly route these domains?
Update 1: Rather than breaking real sites trying this stuff, I just made 2 wordpress installs in the directory tree above. Sorry about the www's. That's what worked for testing purposes.
Here's what happened:
After installing the sites, they worked as expected. I could load the two wordpress sites with either b.campscoreboard.net or campscoreboard.net/b.
However, I got an internal server error on all campscoreboard.net, b.campscoreboard.net, and c.campscoreboard.net after adding the suggested .htaccess of...
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName b.campscoreboard.net
ServerAlias www.b.campscoreboard.net
DocumentRoot /a/b
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName c.campscoreboard.net
ServerAlias www.c.campscoreboard.net
DocumentRoot /a/c
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What do you think I'm doing wrong?
Follow these steps:
a) Create Apache virtualhost:
Read this tutorial.
Example configuration:
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName mudministry.com
ServerAlias www.mudministry.com
DocumentRoot /mudmin/home
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName userspice.com
ServerAlias www.userspice.com
DocumentRoot /mudmin/userspice
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
b) Add wordpress files in /mudmin/home and /mudmin/userspice. Make sure you access these sites first time using the servernames specified above. mudministry.com and userspice.com
This will make sure the your wordpress urls are generated correctly.
c) Use Reverse proxy for mudministry.org
Read this tutorial:
Example configuration:
<VirtualHost 10.10.1.91:80>
ServerName mudministry.org
ServerAdmin webmaster#localhost
## You dont have to keep this /mudministry
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyAddHeaders Off
ProxyPass /home http://mudministry.com
ProxyPassReverse /home http://mudministry.com
ProxyPass /userspice http://userspice.com
ProxyPassReverse /userspice http://userspice.com
</VirtualHost>

Apache2 configuration causing redirect loop

I'm trying to setup my site to use www only, and non-www should be permanently redirected to www. This answer suggested using two virtual hosts, however it causes me to go into a redirect loop.
Here's the configuration for the site:
<VirtualHost *:80>
ServerName www.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
Redirect permanent / http://www.mydomain.com/
</VirtualHost>
When I visit the non-www version of the site it successfully redirects to the www version, however Chrome then tells me that there was a redirect loop.
At first I thought it could be .htaccess in my document root however after removing that file it still happens. It's just a simple Wordpress site.
Can anyone see something wrong with the config that would cause this to happen? If not, how can I narrow down the cause?
You don't need a separate VirtualHost entry for non-www and use ServerAlias instead. Also to redirect to www just use a rule like this:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

Moving WordPress blog from subdomain on same server

I have my website and WordPress installed on a Linode server running Ubuntu.
The directories are:
~/public_html - Website
~/public_blog - WordPress installation
My DNS and site config is set up so that:
hashbang0.com - Points to website in ~/public_html
blog.hashbang0.com - Points to WordPress install in ~/public_blog
Site config as follows:
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName hashbang0.com
ServerAlias www.hashbang0.com
DocumentRoot /home/user/public_html/
ErrorLog /home/user/log/error.log
CustomLog /home/user/log/access.log combined
</VirtualHost>
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName blog.user.com
ServerAlias blog.user.com
DocumentRoot /home/user/public_blog/
ErrorLog /home/hashbang0/log/blog_error.log
CustomLog /home/hashbang0/log/blog_access.log combined
</VirtualHost>
Now, I have had enough of tinkering with PHP, HTML, etc. I want to move my WordPress installation so that visitors to hashbang0.com see the WordPress site. At the same time, anyone with links to the old blog.hashbang0.com (most notably RSS feeds and a few links spattered about which gain a fair amount of traffic, etc.) shouldn't be cut off (possibly be redirected to the appropriate thing on hashbang0.com).
I guess I could possibly change the site config to:
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName hashbang0.com
ServerAlias www.hashbang0.com
DocumentRoot /home/user/public_blog/
ErrorLog /home/user/log/error.log
CustomLog /home/user/log/access.log combined
</VirtualHost>
And I guess I'd need to update the URL in Settings > General?
I don't want to start moving stuff and find I've shot myself in the foot. The WordPress howtos are great, but riddled with if this and if that...
Any help would be very much appreciated.
Ben
Ben,
Your best bet is to litterally move the entire blog folder over to your public folder. In this case, you will want to write a redirect htaccess script on the blog subdomain.
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$ [NC]
RewriteRule ^(.*) http://www.mydomain.com/$1 [L,R]
In a Command Line Interface, CLI,
You would
cp -r ~/public_blog ~/public_html
make sure to make back ups! And when you are all done, create the .htaccess file in ~/public_blog and delete the old files.
You may want to look into adding a 301 Redirect so google knows you moved also.
Before you do anything, create a copy of this file. Then if you mistype anything, you just overwrite the original with the copy.
Currently your website is located in directory public_blog. To have users access this WP from hash bang, you either need to rewrite the DocumentRoot for hashbang from public_html to public_blog or you need to move the entire site directory structure to the root directory in public_html.

Wordpress + Wordpress Network on Single Server conflict

I have two installs of wordpress on a single Amazon EC2 server. One of them is just a regular wordpress install, the other being a wordpress network install, with WP Domain Mapping installed.
So let's say I have four domain names: site.example.com, multisite.example.com, multisite1.com and multisite2.com
All of the domain names are pointing to the same IP address. Multisite1.com and multisite2.com are domain mapped to blogs under the multisite.example.com wordpress network
On my server httpd.conf is setup as follows:
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/site1
ServerName site.example.com
ErrorLog logs/site_error_log
CustomLog logs/site_access_log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite.example.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>
Right now, all of the domains seem to go to the right place - until I start getting to the wp-admin panel.
site.example.com/wp-admin and multisite.example.com/wp-admin appear to work fine.
multisite1.com/wp-admin and multisite2.com/wp-admin both seem to redirect to site.example.com/wp-admin instead of multisite.example.com/wp-admin.
I can't figure out why. I have tried putting all of the domain names in the virtual host as ServerAlias but it doesn't seem to have helped. I've also put in a wildcard ServerAlias under multisite.example.com as well, but no luck.
Any ideas? It is a bizarre install I know, but for the time being for other reasons, I have to get it to work this way. I will eventually separate the two.
Create a new sites-available entry for each of your sub-domain or virtual host for each sub-domain pointing to the same web root and reload the apache. After that all will work fine.
For e.g.
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite1.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite2.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>

Resources