# Linking to pages in protected area

**URL:** <https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 8, 2023, 9:09pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038 "2023-07-08T21:09:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [July 8, 2023, 9:09pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/1 "2023-07-08T21:09:14Z")

</div>

I have created a protected area on a website according to the following cookbook recipe:

> **[Access forbidden](https://getkirby.com/docs/cookbook/security/access-restriction)**
>
> Use Kirby’s authentication system to build login-protected pages.

The protected pages can be found in the subdirectory /closed:

[https://mysite.com/closed](https://mysite.com/closed)

About 100 registered users have access to this protected area (Kirby users without panel access). From time to time I inform these users by email about new content in the protected area and send links to this content, e.g.

[https://mysite.com/closed/very-interesting-article](https://mysite.com/closed/very-interesting-article)

When these users click the link in the email and are not logged in, they get to the home page of the website

[https://mysite.com/](https://mysite.com/)

How could I achieve, that the users get to the login page instead ([https://mysite/login](https://mysite/login)), the URL sent by email remains “cached” and the users get to the target URL after entering their credentials?

[https://mysite.com/closed/very-interesting-article](https://mysite.com/closed/very-interesting-article)

Thanks in advance for any advice!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 8, 2023, 9:33pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/2 "2023-07-08T21:33:02Z")

</div>

You could simply send them to a route path (let’s call it newshandler, but that’s up to you) and add the redirect to as query string, for example

```auto
https://mysite.com/newshandler?user=userid&goto=closed/very-interesting-article

```

Then in your newshandler route, you check if the user is logged in, if yes, you redirect them to the page using the request parameters.

If the user is not logged in, you send them to the login page, attaching the `goto` query param, then let the login controller do the rest, i.e. check if a goto query parameter is set and if so, redirect after successful login.

If you don’t have the userid, because you are sending the link as newsletter, then leave out the part with the user, and redirect to login just with the `goto` arguments.

Of course, what you call the parameters is totally up to you.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [July 9, 2023, 4:48am UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/3 "2023-07-09T04:48:28Z")

</div>

Great! Thank you very much, Sonja!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 9, 2023, 7:30am UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/4 "2023-07-09T07:30:55Z")

</div>

Oh, I missed one step, when you send the form, you have to add the query param to a hidden form field, or you store the goto value in the session in step one (the route), and then remove it again when done in the login controller.

Come to think of it, when you leave out the user handling, you might as well send the user straight to the login page with the query parameter, without the additional route.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [July 10, 2023, 6:04pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/5 "2023-07-10T18:04:37Z")

</div>

Thanks again, Sonja!

I took your suggestion, send the users to the login page and attach the destination as a parameter:

`https://mysite.com/login?target=very-interesting-article`

This works - almost.

The following problem remains: The website in question is bilingual (de/fr). The URL as given above does not work, a URL with language works.

`https://mysite.com/de/login?target=very-interesting-article`

Do you have any suggestion how to get along without mentioning the language in the URL?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 10, 2023, 6:08pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/6 "2023-07-10T18:08:17Z")

</div>

Hm, do you send language specific urls to the users? Do you use the language code for all languages?

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [July 10, 2023, 6:36pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/7 "2023-07-10T18:36:58Z")

</div>

I would prefer, not to send language specific URLs. Would be some additional work for approx. 20 of 100 users in France.

Don´t quite understand your second question. The website contains all articles in German and in French, therefore, I use the language codes across the board.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 10, 2023, 6:48pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/8 "2023-07-10T18:48:16Z")

</div>

> [@steenweg](#):
>
> Don´t quite understand your second question.

What I meant is if your default language uses the language code in the url or not, so let’s say your default language is German, is the url for the german site `mysite.de/de` or just `mysite.de`?

But what I wonder: What was the link your originally wanted to sent the users to? You have to send them to some language version after all?

However, if that doesn’t work, you can still go back to using the original route solution.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [July 10, 2023, 7:05pm UTC](https://forum.getkirby.com/t/linking-to-pages-in-protected-area/29038/9 "2023-07-10T19:05:43Z")

</div>

Thanks, Sonja,

the URL for the German language site is [mysite.org/de](http://mysite.org/de), for the French language site [mysite.org/fr](http://mysite.org/fr).

I will stay with sending “de” URLs for the moment and switch to a route solution in version 1.1 of the site.

Thanks again

Thomas
