This may be rather a niche problem, but I had a Drupal installation on where I wrote various tech-related articles. My plan was to learn about Drupal development whilst having this site set up, but I found that Drupal wasn’t really suited to my needs and that WordPress would be a better fit for the things that I want to do. So I wanted to archive the Drupal installation and get WordPress running on the same domain.

I installed WordPress in a subdomain on the site (I used /bike as I wanted to create a site about my cycling exploits). I wanted to automatically go to the /bike subdomain, but that would prevent access to the previous Drupal installation if I automatically redirected all traffic. It may have been possible to move the Drupal installation to a subfolder but then there would be numerous 404s from any links to it.

In the end, I added a few lines of code to the Drupal index.php script in the home directory of the domain. I added it at the top (but underneath the comments) so it is the first action undertaken.

if ($_SERVER[REQUEST_URI] == "/") {
	header("HTTP/1.1 301 Moved Permanently"); 

What this code does is check to see if users are attempting to go directly to a previous URL from the Drupal installation – if so, then $_SERVER[REQUEST_URI] will not just be a / and so it will ignore the redirect. But if we are just attempting to go directly to the website, it will automatically redirect. So there is still full access to the Drupal installation, whilst the main will redirect to my new cycling website.

Leave a Reply

Your email address will not be published. Required fields are marked *