0

In Meteor, I use the code "window.location.href=..." to redirect people from all www. urls to non www.

Where is the best place to put this code? I've tried putting it inside the Router as well as the Startup/Bootstrap code.

However, no matter what I do, the App loads first, then detects the www. url and redirects me.

What I want is Meteor to redirect ALL www. URLs to non www. before anything is loaded. I understand that htaccess is not possible in Meteor, so what is the alternative in Meteor?

Mcope
  • 781
  • 8
  • 22
  • Do you want users to redirect to non URL's after logging in? – EugenSunic Jan 03 '15 at 10:38
  • I want absolutely no access to www. URLs. If the URL contains www., I want everyone to be redirected to non www. without loading the app. No exceptions at all. Same goes for https:// vs http:// – Mcope Jan 03 '15 at 10:47
  • You could try this, if you didn't already, http://stackoverflow.com/questions/21315896/redirect-after-login-using-meteor-and-iron-router – EugenSunic Jan 03 '15 at 10:56
  • That doesn't work. Any redirect code that is written inside Meteor requires Meteor to load first. So the entire app is loaded, then user is redirected then the entire app loads again. That is exactly what I don't want. – Mcope Jan 03 '15 at 11:04

1 Answers1

0

You need to let the server handle it. The reason why you are having this problem is because you are letting the code do it. Don't do that. There are a billion redirect from www to non www questions and links by doing a search for this using .htaccess.

Put this at the top of your htaccess file and clear your browser cache before testing

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]

If you want to always force https and without the www you can do this

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC,OR]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95