# Redirect to an external site on page load?

**URL:** <https://zola.discourse.group/t/redirect-to-an-external-site-on-page-load/2504>\
**Category:** Support\
**Created:** [March 9, 2025, 1:59pm UTC](https://zola.discourse.group/t/redirect-to-an-external-site-on-page-load/2504 "2025-03-09T13:59:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashantrahul141](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/prashantrahul141/32/1419_2.png) [@prashantrahul141](https://zola.discourse.group/u/prashantrahul141)\
**Post date:** [March 9, 2025, 1:59pm UTC](https://zola.discourse.group/t/redirect-to-an-external-site-on-page-load/2504/1 "2025-03-09T13:59:16Z")

</div>

Hello, I am beginner to Zola, sorry if this question has been asked before I couldn’t find anything.  
How do I redirect to an external url on page load? I want to create routes which immediately redirects to an external site on page load.  
I tried doing

```html
<div onload="javascript:window.location.replace('https://google.com'))">
</div>

```

and

```html
<script type="text/javascript">
window.onload = function () {
  window.location.replace('https://google.com')
  window.location.href = "https://google.com"
}
</script>

```

Didn’t work but then later I created a shortcode `redirector.html`

```auto
<script>
window.onload = function() {
  window.location.href = '{{ url }}'
}
</script>

```

and used it like this

```auto
+++
+++

{{ redirector(url = "https://google.com") }}

```

This does seem to be redirecting but it encoded the url so it doesnt work.

```auto
https://&/#x2F;&#x2F;google.com

```

---

<div class="post-metadata">

**Author:** ![prashantrahul141](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/prashantrahul141/32/1419_2.png) [@prashantrahul141](https://zola.discourse.group/u/prashantrahul141)\
**Post date:** [March 9, 2025, 2:19pm UTC](https://zola.discourse.group/t/redirect-to-an-external-site-on-page-load/2504/2 "2025-03-09T14:19:16Z")

</div>

Nevermind I found it. I had to mark it “safe” in the second approach.  
basically create a `redirectory.html` shortcode with this:

```auto
<script>
window.onload = function() {
  window.location.href = '{{ url | safe }}'
}
</script>

```

and then you can use it on any page like so:

```auto
+++
+++

{{ redirector(url ="https://google.com") }}

```

---

<div class="post-metadata">

**Author:** ![zolappom](https://avatars.discourse-cdn.com/v4/letter/z/48db29/32.png) [@zolappom](https://zola.discourse.group/u/zolappom)\
**Post date:** [March 12, 2025, 11:20pm UTC](https://zola.discourse.group/t/redirect-to-an-external-site-on-page-load/2504/3 "2025-03-12T23:20:57Z")

</div>

Even possible with HTML only!

> <https://stackoverflow.com/questions/5411538/how-to-redirect-one-html-page-to-another-on-load>
