<p>I'm trying to create a mechanism for informing users that a particular entry is not available in the selected language, and providing a link to read the article in an alternative language.</p>

<p>Therefore, if one of my secondary locales returns a 404 for a particular URL and goes to a localised 404 error template, is there a way to check in the 404 template if the corresponding URL path matches an entry in my main locale, so I can link to that entry from the 404 page?</p>

<p>I think what I want is a method for searching for an entry using a string containing the complete URL path, but I don't think that’s available, so what would be the best alternative?</p>

CC BY-SA 3.0
2017-10-23T04:36:59.943Z
I don't think this is possible unless you store every request from each user in a session and check the last one in a 404 request. My question: why do you even show/display links to a 404 request. It's better to not link non existing entries or link them in another local (with a hint) from the beginning. Internal 404 links are no good
Robin Schambach
CC BY-SA 3.0
2017-10-23T08:47:17.683Z
Yes, that's a good point.
Alex H
CC BY-SA 3.0
2017-10-23T08:55:14.320Z
The reason I'm linking to a 404 is because each locale link in the language switcher module is designed to link to the same article in the alternative language, and the client doesn't want to redirect to the locale homepage but to a page that informs them that that page isn't available in the selected language, and provides alternatives. I'll have a think.
Alex H
CC BY-SA 3.0
2017-10-23T09:06:39.270Z
Then you have to create your custom `getUrl()` function.. Go to `BaseElementModel->getUrl()` and you'll see what happens there.. just copy/paste the function in your pluginVariable.php (with the entryId param as) and include a check whether the entry for that local exists and try to fetch the one in your local if not `$url = UrlHelper::getSiteUrl($path, null, null, "your new local eg. fr or en or whatever the handle is");` In your template you just use `{{ craft.pluginHandle.getUrl(entryId) }}`
Robin Schambach
<entries><localization><elementcriteriamodel><404>
If an entry doesn't exist in a locale and returns a 404, how can I check if the entry exists in a different locale?
# If an entry doesn't exist in a locale and returns a 404, how can I check if the entry exists in a different locale?

(Asked by: username_0 on 2017-10-22)

I'm trying to create a mechanism for informing users that a particular entry is not available in the selected language, and providing a link to read the article in an alternative language.

Therefore, if one of my secondary locales returns a 404 for a particular URL and goes to a localised 404 error template, is there a way to check in the 404 template if the corresponding URL path matches an entry in my main locale, so I can link to that entry from the 404 page?

I think what I want is a method for searching for an entry using a string containing the complete URL path, but I don't think that’s available, so what would be the best alternative?

**Tags:** entries, localization, elementcriteriamodel, 404

> **Comments:**
> **username_1**: I don't think this is possible unless you store every request from each user in a session and check the last one in a 404 request. My question: why do you even show/display links to a 404 request. It's better to not link non existing entries or link them in another local (with a hint) from the beginning. Internal 404 links are no good  
> **username_0**: Yes, that's a good point.  
> **username_0**: The reason I'm linking to a 404 is because each locale link in the language switcher module is designed to link to the same article in the alternative language, and the client doesn't want to redirect to the locale homepage but to a page that informs them that that page isn't available in the selected language, and provides alternatives. I'll have a think.  
> **username_1**: Then you have to create your custom `getUrl()` function.. Go to `BaseElementModel->getUrl()` and you'll see what happens there.. just copy/paste the function in your pluginVariable.php (with the entryId param as) and include a check whether the entry for that local exists and try to fetch the one in your local if not `$url = UrlHelper::getSiteUrl($path, null, null, "your new local eg. fr or en or whatever the handle is");` In your template you just use `{{ craft.pluginHandle.getUrl(entryId) }}`  

---

## 0 answers

