Redirect to a specific page when someone comes back to the website

Description

  1. My website is https://androidwedakarayo.com. Still, I am publishing articles in Sinhala, and near future, we hope to publish articles in English.

  2. So I thought to add a language selector for the website as Sinhala and English and if someone selects Sinhala, he will redirect to androidwedakarayo.com/sinhala or someone selects English he will redirect to Android වැඩකාරයෝ - English Bulletine. And also if he comes back to the website he should redirect to the language page that he selected in the previous session.

image
Language selector example

  1. I want to load Sinhala posts in androidwedakarayo.com/sinhala and If someone reads a Sinhala article, the URL should be androidwedakarayo.com/sinhala/postURL.

Question

I want to implement No. 2 and No 3. on my website and how to do it?

Does anyone know how to do this?

You could force all requests to custom page and have that page detect the language and route accordingly.

For example I have this for my site:

routes:
  /:
    data:
      post:
        resource: pages
        type: read
        slug: landing
    template:
      - custom-home

You can create your own custom-home template that has the logic you’re looking for though you have to write custom code and then create new ‘home-en’ and ‘home-sinhala’. At least that’s my suggestion.

Could you please explain this.

Basically the routes says for the front page instead of loading the default show a page with the slug ‘landing’ and use the template custom-home.

In my theme directory I created a new file called custom-home.hbs which sets up my home page with a different view.

This might be helpful: https://ghost.org/docs/tutorials/custom-page-template

1 Like

Thank you @csgeek the link you have given was broken. But I think you meant about the routing and I found it in Ghost Themes - Dynamic URLs & Routing

Thank you for your support. It worked.

But I want to implement the following one also. Could you please help me.

The page i was trying to link you to was this: Create a custom post template in Ghost

But as long as you got it working, it’s all good.

Do you have any idea about this @csgeek

Does anyone know how to do this but lead people to another site? When I send a post as a newsletter and recipient clicks “View Online” I want them to go to my static Nextjs url, not the Ghost url…
I have tried using redirects.yaml and had trouble. Any help welcome.

If you have a ghost page you can always embed a javascript redirect. For example: How To Redirect to Another Webpage

Just I am looking for something handle by cookies. That means once you visited my website and selected Engish, it will store a cookie that you had selected Engish.

When you visit back to my website, it checks the locally stored cookie and redirects to the English content page.

I am not an expert with cookies and I am a beginner in web development. Therefore I need a guide.

You’ll have to do the work. There won’t be a guide that’ll be type this in your html doc to redirect for languages.

Here’s how to set cookies in JS: JavaScript Cookies Then you’ll need some custom code that checks for your cookie and on a particular value redirect.

Here’s how to redirect in Javascript: How To Redirect to Another Webpage

Your landing page needs to invoke that method and redirect the user accordingly.