Maybe not distinctly a Drupal question, I have an older Drupal 7 site that I want to leave up for backlinks, but any new visitors I want to redirect to a new external website. So domain.com would redirect to newdomain.com but domain.com/node/6 is still accessible.

Update: Server is nginx and I don't have access to server settings and routes.

  • Sounds potentially like an htaccess rule. You could write one that matches the domain directly, and that should allow non-homepage URLs to keep working. Maybe something like this in your .htaccess file: stackoverflow.com/questions/42493408/… this should redirect any home request to the new domain, but anything not matching should continue to work. It might need a little massaging for Drupal, but I don't have a way to test this out at the moment. Initial tests here tell me it will work. htaccess.madewithlove.be – Kevin Jan 5 at 21:15
  • Sorry, updated the question it is an nginx server and I don't have access to the nginx routes/settings files. – Kris Robinson Jan 5 at 21:26

It sounds like one thing you could do is edit the themes template.php file and do something like:

 * Implements template_preprocess_html().
function mytheme_preprocess_html(&$variables) {
  if (drupal_is_front_page()) {
    $url = 'http://newdomain.com';
    drupal_goto($url, ['external' => TRUE], 301);
    // perhaps alternatively you could use header();

Outside of doing this at the web server level, it might be the smallest change to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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