I have a multiuser wordpress install which is currently using subdomains. I'd like to migrate it to use subfolder multiuser. I've set up subfolder multi-user and it actually works. Now, I'd like to redirect from the old address to the new address. For instance:
peter.example.com -> example.com/peter
Both domains above are properly added as aliases in OpenShift. To cause the redirect, I created a rewrite rule in the .htaccess file. It looks like this:
RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/%1/$1 [R=301,L]
This results in a redirect loop. Inspecting this, a simple request on peter.example.com produces:
HTTP/1.1 301 Moved Permanently
Date: Mon, 05 Jan 2015 03:30:58 GMT
Server: Apache/2.2.15 (Red Hat)
Location: http://peter.example.com/peter/
Content-Length: 335
Content-Type: text/html; charset=iso-8859-1
Accept-Ranges: none
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://example.com/peter/">here</a>.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at peter.example.com Port 80</address>
</body></html>
The return value is correct, as is the URL in the body; so I know my RewriteRule is being evaluated. However, the URL in the Location header is incorrect. Why? It seems to me as if OpenShift is mangling this header causing the redirect to fail.
Is this a bug in OpenShift? In my RewriteRule? Does anyone have a suggested workaround?