views:

48

answers:

2

If I had a normal website this would be a simple enough fix... but I've built my site on tumblr so I need a workaround. Every page runs off of the same code, so any solution script is going to run on every page.. can't quite figure this one out (did I mention I'm a total n00b?). There are lots of answers to questions LIKE this one, but I couldn't quite find the right syntax I suppose to answer this question...

The goal here is, if some goes to just the raw domain name, in this case milliondollarextreme.tv --> I'd like it to redirect to milliondollarextreme.tv/tagged/videos.

In any other case, by that I mean, if there is anything appended to the end of the domain name already, such as:

  • milliondollarextreme.tv/permalink/91298132843
  • milliondollarextreme.tv/tagged/blog
  • milliondollarextreme.tv/contact.htm

I don't want there to be any redirection going on. I only want the redirect to 'fire' really the first time the person types in the domain -- milliondollarextreme.tv

The trick here, the reason why I am asking (I did a search and 1000 apologies if this has been asked elsewhere, I just couldn't find it) is that the script has to run on every page, because it's hosted on tumblr, so every page is driven by the same code.

Any ideas? Thanks in advance.

+2  A: 
<script>
if( window.location.href == "http://milliondollarextreme.tv"   ||
    window.location.href == "http://milliondollarextreme.tv/"  ||
    window.location.href == "http://www.milliondollarextreme.tv"   ||
    window.location.href == "http://www.milliondollarextreme.tv/") {

  window.location.href = "http://www.milliondollarextreme.tv/tagged/videos/";

}
</script>

What should happen when someone enters to http://milliondollarextreme.tv/ for the second time?

Gerardo Grignoli
I can only post comments to my own answers for now (lack of reputation), but +1 to Matthew for introducing pathname property, that I wasn't aware of...
Gerardo Grignoli
Gerardo thanks for the help brotha
Sam Hyde
+4  A: 

This will simply redirect any visit to milliondollarextreme.tv/ to milliondollarextreme.tv/tagged/videos

if(window.location.pathname == '/')
{
  window.location.pathname = '/tagged/videos';
}

However, it will do it every time they go to the root; like Gerardo, I'm not clear if that's what you want.

Matthew Flaschen
yo man... that is exactly what I needed. Thank you so much dude. I'm not a programmer or anything or professional I'm just hacking together a personal website like an idiot over here -- this community is so awesome. thanks very much!!!!!
Sam Hyde
I can comment now!Sam, you should accept this answer, it's better than mine.
Gerardo Grignoli