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

2
  • What do mean by all 'incoming' traffic. All visitors where the referrer is from another domain and not your website? Or first time visitors? Commented Oct 8, 2013 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
    Commented Oct 9, 2013 at 20:25

3 Answers 3

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.

4
  • I should clarify, I am looking to do this in the interface, not programmatically.
    – mattcoker
    Commented Oct 9, 2013 at 20:24
  • 1
    drupal.stackexchange.com/questions/19065/… may help you out, but my htaccess solution is the way to go Commented Oct 9, 2013 at 20:37
  • Does this redirect all requests to the homepage or only incoming traffic (from another domain) ? Commented Oct 10, 2013 at 16:41
  • This redirects all urls on the website domain to the homepage, essentially all domain.com/* to domain.com/ Commented Oct 10, 2013 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

2
  • I should clarify, I am looking to do this in the interface, not programmatically.
    – mattcoker
    Commented Oct 9, 2013 at 20:25
  • So probably you will be able to do this with rules. You can take a look.
    – Enxebre
    Commented Oct 10, 2013 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 and acknowledge you have read our privacy policy.

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