1

Seems this server redirect question may be better suited for serverfault than wordpress stack exchange.

Originally we had a static marketing site at example.com and the wordpress blog hosted at www.joesexample.com/blog.

We are now moving that blog to blog.joesexample.com. However this blog is hosted on a different server (same server name but different WP specific host).

And the original marketing site is still hosted on the original other server.

So presumably on the original host in www.joesexample.com/blog we will empty that folder and add a .htaccess that will need a 301 redirect so anyone going to joesexample.com/blog will be permanently redirected to blog.joesexample.com as well as well as redirecting all posts to the new location. For instance redirecting www.joesexample.com/blog/2014/01/my-post-title/ to blog.joesexample.com/2014/01/my-post-title/

Based on results from Google would the following work:

RewriteEngine ON    
RewriteCond %{REQUEST_URI} ^/blog
RewriteRule ^(.*)$ http://blog.joesexample.com/$1 [R=301,L,P]

Wasn't sure since they are on different servers (ips) if that would matter, I'm thinking it won't since the domain name is the same and also if that rule will only cover the main blog homepage redirect or all the posts, I'm not sure if it will redirect the posts that are in year/month/post title format.

Finally, the reason why I'm asking here first rather than of course simply testing it myself is because it is another person with access to this particular server so I want to be fairly confident it will work before I have them try.

UPDATE - Went ahead and tried having the person use the above htaccess. It all appears to be working except it's not rewriting the URL in the url field.

What I mean is if I go to http://www.joesexample.com/blog it is now properly showing the content from http://blog.joesexample.com however the URL field still shows http://www.joesexample.com/blog. So it sounds like I still need an additional htaccess rule that will change the URL appearance in the URL bar. Any thoughts?

1

You are using the [P] flag which causes the request to be handled by mod_proxy.

If you want the browser to be redirected using a HTTP 301 code and therefore display the real URL then your flags should only be [R=301,L].

This might help you:

  • Bam, that was it, works now, and appreciate the link. One thing I notice is it only redirects if the original url has www in front (which is what I want) but was curious how it would need to be modified if the original site was joesexample.com/blog instead of joesexample.com/blog. If your not sure no worries and marking this answer as correct since it answers my original question. Thank you! – cchiera Jan 16 '14 at 1:17
  • Technically: joesexample.com and www.joesexample.com are two different websites. You should have the ability to create an alias (ServerAlias) in the apache config and create another rewrite rule below this one that will redirect joesexample.com to www.joesexample.com. I hope I'm making myself clear. – SamK Jan 16 '14 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.