Merge lp:~davidc3/developer-ubuntu-com/redirects-on-404-1 into lp:developer-ubuntu-com

Proposed by David Callé
Status: Merged
Approved by: David Callé
Approved revision: 208
Merged at revision: 207
Proposed branch: lp:~davidc3/developer-ubuntu-com/redirects-on-404-1
Merge into: lp:developer-ubuntu-com
Diff against target: 53 lines (+44/-1)
1 file modified
templates/404.html (+44/-1)
To merge this branch: bzr merge lp:~davidc3/developer-ubuntu-com/redirects-on-404-1
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Approve
Review via email: mp+290963@code.launchpad.net

Commit message

Hardcoded redirects on 404 page.

Description of the change

Hardcoded redirects on 404 page.

- Checks if beginning of path matches a redirect
- Replaces by new uri
- Checks if page exists
- Redirects

To post a comment you must log in.
208. By David Callé

Remove newlines

Revision history for this message
Daniel Holbach (dholbach) wrote :

Had to turn off DEBUG = True, but worked nicely for me.

+1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'templates/404.html'
2--- templates/404.html 2014-12-19 19:23:06 +0000
3+++ templates/404.html 2016-04-05 10:03:24 +0000
4@@ -6,5 +6,48 @@
5 {% block nav_secondary %}{% endblock %}
6
7 {% block content %}
8-<div class="row">{% trans "This page does not exist. If you feel that this is an error, please <a href='https://bugs.launchpad.net/developer-ubuntu-com/+filebug'>file a bug</a>." %}</div>
9+
10+{% get_current_language as lang %}
11+
12+<div class="row">{% trans "This page does not exist or has been moved. If you feel that this is an error, please <a href='https://bugs.launchpad.net/developer-ubuntu-com/+filebug'>file a bug</a>." %}</div>
13+
14+<script>
15+
16+ var path = "{{ request.path }}";
17+
18+ var move = [{'from':'/apps/', 'to':'/phone/apps/'},
19+ {'from':'/scopes/', 'to':'/phone/scopes/'},
20+ {'from':'/web/', 'to':'/phone/web/'},
21+ {'from':'/start/ubuntu-for-devices/', 'to':'/phone/devices/'},
22+ {'from':'/start/platform/', 'to':'/phone/platform/'},
23+ {'from':'/start/quality/', 'to':'/phone/platform/quality/'},
24+ {'from':'/start/ubuntu-sdk/', 'to':'/phone/platform/sdk/'},
25+ {'from':'/start/', 'to':'/phone/'}]
26+
27+ function returnStatus(req, status) {
28+ if(status == 200) {
29+ window.location = new_path
30+ }
31+ }
32+
33+ function fetchStatus(address) {
34+ var client = new XMLHttpRequest();
35+ client.onreadystatechange = function() {
36+ if(this.readyState == 4)
37+ returnStatus(this, this.status);
38+ }
39+ client.open("HEAD", address);
40+ client.send();
41+ }
42+
43+ for (var i = 0; i < move.length; i++) {
44+ var m = "/" + "{{ lang }}" + move[i]['from']
45+ var t = "/" + "{{ lang }}" + move[i]['to']
46+ if (path.lastIndexOf(m, 0) === 0) {
47+ var new_path = path.replace(m, t);
48+ fetchStatus(new_path)
49+ break;
50+ }
51+ }
52+</script>
53 {% endblock %}

Subscribers

People subscribed via source and target branches