I need to redirect a Blog on a subdomain running on Ghost and all its posts to a new location. The currently sits in http://blog.example.com
and needs to be redirected to http://example.com/blog/
For the original Ghost blog, Apache was used as a proxy, because Ghost is running on node.js. For that reason, I cannot simply use a .htaccess
in the root folder of the Ghost installation.
I used a 301 redirection generator to set all required redirects and then placed the code directly in etc/apache2/sites-enabled/000-default.conf
, like so:
<VirtualHost *:80>
ServerName blog.example.com
Redirect 301 / http://example.com/blog/
Redirect 301 /post-title-1/ http://example.com/blog/post-title-1.html
Redirect 301 /post-title-2/ http://example.com/blog/post-title-2.html
Redirect 301 /post-title-3/ http://example.com/blog/post-title-3.html
</VirtualHost>
I then restarted the server.
http://blog.example.com
is now correctly redirecting to http://example.com/blog/
, but the individual posts are pointed to the wrong location. Instead of applying the new location, e.g. post-title-1.html
, they are pointed to http://example.com/blog/post-title-1/
, which logically throws a 404 error.
Would appreciate your advive, how to solve this.
You have rules in wrong order i.e most generic catch-all rule is your first rule and taking precedence over rest of the rules.
Use:
<VirtualHost *:80>
ServerName blog.example.com
Redirect 301 /post-title-1/ http://example.com/blog/post-title-1.html
Redirect 301 /post-title-2/ http://example.com/blog/post-title-2.html
Redirect 301 /post-title-3/ http://example.com/blog/post-title-3.html
Redirect 301 / http://example.com/blog/
</VirtualHost>
Make sure to clear your browser cache before testing this.