Javascript: creating a "weird" conditional redirect

If I had a regular site, that would be a fairly simple fix ... but I built my site on tumblr, so I need a workaround. Each page is launched from the same code, so any script solution will run on each page .. cannot fully understand this (did I mention that I am full n00b?). There are many answers to this LIKE questions, but I could not find the correct syntax, I suppose, to answer this question ...

The goal is that if someone only goes to the raw domain name, in this case milliondollarextreme.tv → I would like him to be redirected to the milliondollarextreme.tv/tagged/videos file.

In any other case, I mean if something has already been added to the end of the domain name, for example:

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

I do not want the forwarding to continue. I only want the redirect to "fire" really the first time a person enters a domain - milliondollarextreme.tv

The trick here, the reason I'm asking (I did a search and 1000 apologies if this was asked elsewhere, I just couldn't find it) is that the script should run on every page because it was hosted on tumblr , so each page is controlled by the same code.

Any ideas? Thanks in advance.

+3
2
<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>

, - http://milliondollarextreme.tv/?

+2

milliondollarextreme.tv/ milliondollarextreme.tv/tagged/videos

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

, , ; , , .

+4

Source: https://habr.com/ru/post/1765219/


All Articles