301 Permanent Moves from a Sub-directory to another server when Redirect from Apache won’t work

Posted by andyk - 20/05/10 at 08:05 pm

I had a problem  the other day where I had to move my server to a new server location…  In my case I was moving the support pages for my Wordpress Plugin “Share and Follow” from my Phat-Reaction server to a new server devoted to Share and Follow.

To make it a little more difficult I need to only move a sub-directory to the new server and not the whole domain….  this meant that I was moving
Source: http://phat-reaction.com/share-and-follow/   (and all sub-directory contents)
to
Destination: http://share-and-follow.com/wordpress-plugin/

At the source there were many pages below the /share-and-follow/  subdirectory, all delivered via Wordpress on Apache.  In fact the pages used up to 3 levels of sub-directory below this point.

So I tried to use the Apache Redirect command inside both <Directory> and <VirtualServer> tags but to no avail. In fact when I contacted my hosting company they told me point blank that it could not be done with their server and that 301 Redirect’s could not work when going to an external server.  Not sure I believe that, but no matter what I tried I could not make the standard Apache method work.

To make it work I chose to use PHP and header() commands along with a few extra little bits. Here is the process I took to move it all

  1. Changed the URL inside the Wordpress settings to the new URL
  2. Made a back up of the Database
  3. Placed the new .htaccess in the sub-directory
  4. Placed the new index.php in  the sub-directory
  5. Deleted all traces of Wordpress from the directory and sub-directories

In essence what it does is use Mod-ReWrite to tell the server that all access to the server below the /share-and-follow/ directory should actually load /share-and-follow/index.php.  So it did not matter if it was /share-and-follow/documentation/working-with-themes/  or /share-and-follow/my-stats.html  it would always load the same index.php.  this is all controlled by the .htaccess file.

example .htaccess


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /share-and-follow
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /share-and-follow/index.php [L]
</IfModule>

remember to change the settings to be as you need for your server. For me I was working in the share-and-follow sub-directory. The only lines that need to be changed for your purpose is RewriteBase and RewriteRule. RewriteBase should point at the sub-directory that you want to move, RewriteRule should point at the file you want to automatically load to deal with the redirection.

Once the URL rewrite is in place, all that is left is to configure the php side of things.

example index.php


<?php
/*
 * This file simply redirects with a 301 to a new page with the same name when used in conjunction with a .htaccess
 *
 * @param $stubOld = the Stub URI that will be replaced with the new URL
 * @param $stubNew = the new URI location for the files.
 */

$stubOld = 'http://phat-reaction.com/share-and-follow/';
$stubNew = 'http://share-and-follow.com/wordpress-plugin/';
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
$url = curPageURL();
$url = str_ireplace($stubOld ,'' , $url);

header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$stubNew.$url);
flush();
?>

In this one you only need to change two things. The $stubOld = Old Source URL and $stubNew= New Destination URL. By changing these two items a URL such as http://phat-reaction.com/share-and-follow/documentation becomes http://share-and-follow.com/wordpress-plugin/documentation

And the great part is that Google loves it when you do things this way with a 301 error (Moved Permanently).

Enjoy and share it with your webmaster buddies. Here are the files if you want to download them

Share and Follow wordpress plugin released

Posted by Phat Reaction - 09/04/10 at 11:04 am

After being fed up with most of the other share and follow link systems I decided to build my own. The issues as I saw it was

  1. Links often went via javascript to a 3rd party like AddThis
  2. No control over if things are in a new window or in the same one
  3. pagerank give away
  4. javascript needed to use the systems on screen from AddThis and others
  5. limited display setup
  6. Only share links and no follow links
  7. all or nothing approach from the majors, all pages or posts or nothing
  8. No widget control, no theme tags, no shortcode


So those were the bits that were missing, so I created a system that dealt with all of those issues and more.  We now have widgetized sharing and following, shortcode availabity, multi-size icons (16, 24, 32, 48, 60 px), follow tab in either the top/bottom/left/right side of the screen, funky text replacement option for follow bar.

Basically it’s got most things going….. and is currently being re-developed with more functions and features for version 2.

take a good look at the share and follow plugin for wordpress

Stage 2 on the cards for Unselfish Designs

Posted by Phat Reaction - 10/03/10 at 10:03 pm

After getting a simple blog to help show off her products Wendy is now ready to take unlsefish designs to the next level with a bunch of new features.

  • T-shirt builder
  • Share links
  • Social networking
  • Sales order processing
  • A change in direction on design and layout

We’re looking forward to all the challenges she can throw at us.

New Video Service – Phat Reaction Videos

Posted by Phat Reaction - 09/03/10 at 02:03 pm

We’ve been busy and have created our own Videowall Blog Website (phat reaction videos). It connects up the videos of youtube and the webservices of various affiliate programs including Amazon’s. This system allows viewers to watch a complete playlist of youtube videos without having overlaid advertisements (We pop them on the side in a retractable menu system) and in almost full screen as standard, and with a small press of the f11 button as big as the display.

Not only have we created the website, we have also created a simple Facebook application (phat reaction videos on facebook) to show the same playlists.

The blog will be focusing on Music, Sport, Comedy and Extreem Sports

H2A Fitworkout site online

Posted by Phat Reaction - 06/01/10 at 02:01 pm

Yep, that’s another site under my belt…. This time it is one for a personal trainer here in Amsterdam. Hakima Hamimi wanted a site that stood out from the crowd and found that all the other personal trainer sites were not to her liking. I showed her my back catalog of websites that I have made and she decided that she really liked the Denon Boundless Microsite and wanted one very similar.

So with that in mind we created the site H2A-fitworkout.com and as it is the Netherlands she needed it to be in two languages (english language version, dutch language version). Again the site was based on wordpress to quicken the developement time.

In future she may choose also to add some music to the site to liven it up a little, but for now she is one satisfied customer.

Why I use Wordpress for nearly every install I make

Posted by Phat Reaction - 27/11/09 at 02:11 pm

I was feed up with re-doing the same things time and time again

By using wordpress external site I am able to remove a bunch of my standard work like adding content , setting up the head section or configuring my layout areas.  They are now all pre-configured inside my own hand made made theme, and from there on in I just change the CSS and made wordpress theme changes as needed by the client.  Most likely it saves me 5 hours on each install.

And to be honest, I hope the ease of wordpress to use will enable a site to grow quickly, even if it is just a 1 page advert. Possibly the most sucessful wordpress install that I have made so far would be The Commonwealth Conversation external site.  This site has had over 30,000 visitors and 1000 comments anf got to page rank 7 in about 4 months, not many sites can say that.

Why I work a lot with freelance designers

Posted by Phat Reaction - 27/11/09 at 01:11 pm

It’s because I can make their pritty designs perform in the way that they envisage

Yes thats why they do it, I can do what they cannot.  As I am not a classic graphic artist, I do not have any input towards their designs except how to turn it from a flat single layer into a multi-layered interactive webpage. They rely on me to show them to latest and greatest out there on the web so that they can encorporate it in to their work.

Not only do I code it the way they want it, but also in the time frame that they need it done by.  As you can imagine, it’s really important to them that they can get the right staff that can cut up their design and make it run as quick as possible over the internet…

I like it this way, I am their coder, they are my designers. Together we create proper internet magic.

Why I do so much work for advertising agencies and communications beuros

Posted by Phat Reaction - 27/11/09 at 01:11 pm

Advertising work, yes please

I get lots of requests from Advertising agencies and communcations beuros to perform coding work for them.  This for me is great work as I get chance to show off my skills, but also for the agency it is great as…

  • I have no ambition to become an art director
  • They usually cannot afford to employ a web coder full time
  • They get to pull on my RGB (screen) skills as they are use to a CMYK (print) world
  • The only staff that they can get to work in house on web things tend to have a maximum of 2 years web experience in very small situations. Not 15 years working for some of the largest corporations in the world.
  • I work to my own agenda, which can mean turning round 40hours of work in a 3 days or working at weekends.

And it does not stop with just the web coding, I can also advise or install any kind of supporting hardware or software infrastructure.

In short, it works out great for all.

The who v. fatboy slim

Posted by Phat Reaction - 24/11/09 at 12:11 pm

I was insipred the other day and decided it was time to make my first audio mashup. I chose to use The Who ‘I can’t explain’ and FatBoy Slim ‘Going out of my head’.
Phat Reaction – Who me out of my brain

It’s already got some airplay, and nothing but good vibes from all DJ’s,  so I am dead happy.

Want to be able to play video content on your PS3 without getting DLNA errors?

Posted by Phat Reaction - 24/11/09 at 10:11 am

Being the techie fool that I am, it was a breeze for me to setup my latop with a massive external hard disk that manages all of my video content.  The only problem I found almost instantly was that playstation3 uses DLNA to talk between the media server and the it.  DLNA is crappy at the best of times and when used on my playstation in tune with TVersity I found it was all kinds of  wrong, loosing audio and video all over the place and often crashing.

Check out the full instructions I made with you tube videos on how to do it.  It even covers converting from most formats into a playstation playable one.

Here’s a quick process overview