0

Let me further explain the title.

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 Answer 1

0

You need to revise your last rule

RewriteRule ^blog(.*)$ http://blog.joesexample.com/$1 [R=301,L]

I think that should do it. Previously you were grabbing 'blog' and adding it to the end of the url.

5
  • Ah that makes sense. Going to try it now and will let you know how it goes. Jan 15, 2014 at 19:51
  • We tried but that change causes forbidden errors. Any thoughts? I'll keep researching in the mean time too. Jan 15, 2014 at 19:58
  • You may need a slash in front of blog to work. I edited the line. Either ^/blog(.*) or ^/blog/(.*)
    – user42826
    Jan 15, 2014 at 20:14
  • Doesn't seem to work. I decided to test more simple directs such as redirecting www.joesexample.com to blog.joesexample.com which I was able to get working with: RewriteEngine On Options +FollowSymlinks RewriteCond %{HTTP_HOST} ^(www\.)?joesexample\.com$ [NC] RewriteRule ^ blog.joesexample.com [R,L] and putting that in the root directory. Not sure if there is a way to modify that so it can instead redirect /blog (and any posts in it. Or if there is another change I can try based on your version? htaccess reg expressions are never fun! Jan 15, 2014 at 20:51
  • Got it: So my original one I just need to remove the P like you did in yours but not add the ^blog you had in yours. Going to mark yours as correct tho since the best answer. Thanks! RewriteEngine ON RewriteCond %{REQUEST_URI} ^/blog RewriteRule ^(.*)$ blog.joesexample.com/$1 [R=301,L] Jan 16, 2014 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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