By tsangk
Description
Note: as of the 19th November 2012, Wikidot has implemented a full solution which no longer requires this snippet. View their solution here.
While Wikidot is a wiki platform, some users might wish to show users a more useful message when a page doesn't exist. With this snippet, you can redirect users to a custom 404 page and still get access to create the page using the standard /edit/true URL tags.
Following the tradition of James' JS-based snippets, I too will show the "framework".
Attributes
attribute | required | allowed values | default | description |
---|---|---|---|---|
url | yes | valid URL or website address | none | Specifies the URL to redirect the user to when a page doesn't exist |
Code
You will need to copy the code into the side bar (usually nav:side):
[[include :snippets:404-redirect
|url=http://www.wikidot.com
]]
Link to edit
You can also include a link to create the page that wasn't found. Simply add the following line to your 404 page:
[[include :snippets:404-link
|label=Click here to create the page
|width=200px
|height=30px
]]
[!-- Note, all fields are optional --]
In action
It's currently in action on the Community site as well as in my personal sandbox:
Wikidot Community:
thispageblahblah — this page doesn't exist, it'll be redirected to the 404 page
404 — the 404 landing page
Community Home Page — the page exists, so we're not redirected to the 404 page :)
My Sandbox:
npr:pageexist — this page exists, and isn't redirected to the 404 page.
npr:doesntexist — this page doesn't exists, and will be redirected to the 404 page.
Changelog
- 27th Aug 2012: decreased iframe size by 124 bytes. Hopefully this will make redirection that little bit faster.
- 28th Aug 2012: added "create page" functionality in 404 page. Simply include [[include :snippets:404-link…
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by tsangk
URL Title with Slash Redirect - 04 Jan 2018 11:32
Custom HTML Blocks - 25 Oct 2012 11:30
Syntax Highlighter - 16 Feb 2012 01:45
Conditional Blocks - 15 Feb 2012 00:36
Rate this solution
If you think this solution is useful — rate it up!
I like the 404 redirect and I went to this page (http://ktsangsb.wikidot.com/npr:pageexist) and put the numbers and deleted the number and put it where it was. So yea, I hope I didn't broke the code. I don't know if the page is locked or not.
Website - Stories, coding, health and etc.
Linktree - Contact, information and etc.
Got it going. Thanks!
There's a newpage-button snippet on a page and I want to take them back there if they click cancel. But I must have done something silly. I'll check it again.
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
No it's not working. As soon as I press the newpage button snippet instead of taking me into the dataform it re-directs me. I want that bit but the user needs to edit the dataform first. It works on your site, the community site and several of my other sites. The only difference here is that the site is an SSL site, could that be the problem?
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Yes, it appears to be an SSL issue. The iframe included was set with http://. I've fixed this now. Please test :)
Kenneth Tsang (@jxeeno)
Sorry for being slow to test this. Yes it now works fine on my SSL site. Thanks.
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Kenneth et al, I was wondering if there is a way that this excellent snippet can be extended (or a new one created) to cover the situation when then user presses the Cancel button while editing a new dataform.
At the moment it just takes them to the standard "This page does not "yet" exist" screen, but it would be better if the redirect can be used to take them back to the page they came from. Will we have to wait for wish:247 to be implemented or is there something clever you can do here?
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Hi Rob,
I don't know if I understand fully what you mean here. I've created a data form on my sandbox (http://ktsangsb.wikidot.com/npr:test/edit/true) and I included this snippet on the sidebar… and when I click cancel, it'll redirect me to the 404 page.
So, are you after a way to redirect the user back to the referrer URL rather than a static 404 page?
Kenneth Tsang (@jxeeno)
Although the browser loads two pages instead of one this snippet works fast. Since I do not JavaScript my Wikidot-knowledge is a bit limited. But thanks a lot for this snippet because I waited so much Wikidot staff to implement it.
Best regards,
Vlad
This is a great solution to our long-time needed feature! Well done!
However…
No, the JavaScript code doesn't seem to resemble anything I've coded… I don't think you need to credit me for your hard work here!
Or was this referring to the /nav:side & /nav:top technique I created for the Per Category CSS module?
Ah, well:
The original code (first version) resembled your iframe redirect snippet. Since I had basically copied the code and added lines before and after in the Javascript, I decided to change the comment line — rather than removing it.
I then removed all of the <html>, <body> and <head> to help "speed up" the load time.
So… yeah…
Kenneth Tsang (@jxeeno)
Just had a chance to implement it on one of my own sites — it works really well. Nice job tsangk (and James Kanjo too, who created the original code that you worked from).
In order to have a separate 404 page per category, official support for this feature would still be nice to have. But you've come up with a good alternative in the meantime, and it's extremely simple to implement!
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
Yes, I would love to see official support too.
Thanks :)
I've also added a new include, [[include :snippets:404-link… for creating a link in the 404 page which will allow users to create the page easier. It's 100% SUO capable. I've implemented it in the community site.
Kenneth Tsang (@jxeeno)
And Rob has made a wonderfull community 404 page:
( Sorry, Rob , I cannot stop to post this here..)
http://community.wikidot.com/404 (**Hmmm…..we couldn't find that one **)
Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.
Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?
That's good, well done Kenneth. I've added it to the Community site.
One thing I noticed is there is a lag of a couple of seconds while the "normal" page not found displays before the re-direct happens. Is this due to the html blog in the framework and, if so, the the framework really necessary?
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Thanks Rob :)
Yes, I noticed the lag in redirection too — but I think it's a characteristic of the Javascript-based redirection method. A normal redirect would simple send headers for redirection whereas the javascript method requires the loading of the parent page and the redirection child frame before the actual redirection takes place.
Kenneth Tsang (@jxeeno)