In the past few days I realized that I needed a personal home page, with all my information, such as works, skills, contact info etc.., so I started to build a simple HTML+JS page.

So doing, I wanted to migrate my personal server from Digital Ocean to Scaleway, for economy reasons.

But there were a problem, my domain name is already occupied by my personal blog, this one. 
I couldn’t upload my new "fantastic" Home Page before changing my blog url.

This blog uses Ghost, a new kind of blogging platform, created for a simple and immediate writing. There aren’t so much docs around the web so I had to create something by myself.

Furthermore, since I love complicating my life, the server I am using is configured to host NodeJS apps alongside normal Apache software, since some of my website are built with WordPress or Raw PHP.

My NodeJS installation is proxied by Apache by using this site configuration:

NameVirtualHost *:80
<VirtualHost *:80>
	ServerName www.giorgioromano.it
	ServerAlias gioro.me,www.gioro.me
	ProxyRequests off
	ProxyPass /http://127.0.0.1:2368/
	ProxyPassReverse / http://127.0.0.1:2368/
</VirtualHost>

<VirtualHost *:80>
    ServerName giorgioromano.it
    Redirect permanent / http://www.giorgioromano.it/
</VirtualHost>

Firstly, I had to update this configuration: the new url of my website is www.giorgioromano.it/blog

NameVirtualHost *:80
<VirtualHost *:80>
	ServerName www.giorgioromano.it
	ServerAlias gioro.me,www.gioro.me
	ProxyRequests off
	ProxyPass /blog http://127.0.0.1:2368/blog
	ProxyPassReverse /blog http://127.0.0.1:2368/blog

	<Directory "/var/www">
	    Options Indexes FollowSymLinks 	MultiViews
	    AllowOverride All
	    Order allow,deny
	    allow from all
	</Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerName giorgioromano.it
    Redirect permanent / http://www.giorgioromano.it/
</VirtualHost>`

Then I had to update the config.js in ghost folder, adding /blog at the end of the url

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment.
    // Configure your URL and mail settings here
    production: {
        url: 'http://www.giorgioromano.it/blog',
.......

Now that the first step is done and so the new url the Blog is loading. 
But the relative urls of images, links, and files were the old ones, so I opened phpmyadmin and searched in the whole database the instances of "www.giorgioromano.it/" and I had changed them to "www.giorgioromano.it/blog".

The last step was the redirect of the old urls.
I couldn’t use a generic Rewrite Rule , because on the root of my domain I had to upload my new personal website.

This is my apache configuration for the html website:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	
	<Directory "/var/www">
	   Options Indexes FollowSymLinks MultiViews
	   AllowOverride All
	   Order allow,deny
	   allow from all
	</Directory>	
</VirtualHost>

So I created a .htaccess file in my root giorgioromano.it directory and I added a line for every link I had to redirect:

Redirect 301 Style

Redirect 301 OLDPATH NEWPATH

.htaccess

RewriteEngine On
Redirect 301 /welcome-to-ghost-2/ /blog/welcome-to-ghost-2/
Redirect 301 /dal-2008-a-oggi/ /blog/dal-2008-a-oggi/
[..]

And now my blog is migrated without errors.