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 VranckxCommented 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.– mattcokerCommented Oct 9, 2013 at 20:25
Add a comment
|
3 Answers
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. Commented Oct 9, 2013 at 20:24
-
1drupal.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
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. Commented Oct 9, 2013 at 20:25
-
So probably you will be able to do this with rules. You can take a look.– EnxebreCommented Oct 10, 2013 at 7:21
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]