1

How can I set Drupal 7 so that all incoming traffic is redirected to the homepage? I need to ensure all visitors go to the homepage, even if they click a link on some other site that links to example.com/section/node-1

  • What do mean by all 'incoming' traffic. All visitors where the referrer is from another domain and not your website? Or first time visitors? – Mike Vranckx Oct 8 '13 at 22:04
  • I mean all referrers from a domain that isn't my website, first time visitor's don't matter. I should clarify, I am looking to do this in the interface, not programmatically. – mattcoker Oct 9 '13 at 20:25
1

You could do this easier in your .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/$
RewriteRule $ / [R=302,L]

Put this at the bottom of your .htaccess file and you're set.

  • I should clarify, I am looking to do this in the interface, not programmatically. – mattcoker Oct 9 '13 at 20:24
  • 1
    drupal.stackexchange.com/questions/19065/… may help you out, but my htaccess solution is the way to go – Scott Joudry Oct 9 '13 at 20:37
  • Does this redirect all requests to the homepage or only incoming traffic (from another domain) ? – Mike Vranckx Oct 10 '13 at 16:41
  • This redirects all urls on the website domain to the homepage, essentially all domain.com/* to domain.com/ – Scott Joudry Oct 10 '13 at 17:33
0

You could do something like this:

function yourmodule_init() {
  $destination = drupal_get_destination();
  if ($destination['destination'] != variable_get('site_frontpage', 'url-home')) {
    drupal_goto('<front>');
  }
}

And you Can add to th if statement your custom conditions

Hope this helps

  • I should clarify, I am looking to do this in the interface, not programmatically. – mattcoker Oct 9 '13 at 20:25
  • So probably you will be able to do this with rules. You can take a look. – Enxebre Oct 10 '13 at 7:21
-1

Here are rewrite conditions to redirect all incoming traffic (from another domain) to the homepage. Put this in the .htaccess file.

Don't forget to update the URL with your correct website domain.

RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)*yourdomain\.com 
RewriteRule / http://www.yourdomain.com [R=301,L]

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.