.autoRedirect 2.85 KB
Newer Older
Laurent Heirendt's avatar
Laurent Heirendt committed
1
2
<html>
  <head>
Laurent Heirendt's avatar
Laurent Heirendt committed
3
4
5
6
7
8
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
    function UrlExists(url, cb){
        jQuery.ajax({
            url:      url,
            dataType: 'text',
Laurent Heirendt's avatar
Laurent Heirendt committed
9
            type:     'GET',
10
            cache:    false,
Laurent Heirendt's avatar
Laurent Heirendt committed
11
12
13
14
15
16
            complete:  function(xhr){
                if(typeof cb === 'function')
                cb.apply(this, [xhr.status]);
            }
        });
    }
Laurent Heirendt's avatar
Laurent Heirendt committed
17
18
19
20
21
22

    // define URLs
    var internalURL = 'https://r3-core.pages.uni.lu/howto-cards-internal';
    var externalURL = 'https://r3.pages.uni.lu/howto-cards';

    UrlExists(internalURL+'/index.html', function(status){
Laurent Heirendt's avatar
Laurent Heirendt committed
23
24
        var s = window.location.href;
        var pathArray = s.split('?');
25

Laurent Heirendt's avatar
Laurent Heirendt committed
26
        // cut the query if it exists
Laurent Heirendt's avatar
Laurent Heirendt committed
27
        if (pathArray.length > 1) {
Laurent Heirendt's avatar
Laurent Heirendt committed
28
            sub = pathArray[1];
29
30
31
        } else {
            sub = '';
        }
Laurent Heirendt's avatar
Laurent Heirendt committed
32

Laurent Heirendt's avatar
Laurent Heirendt committed
33
34
        if(status === 200){
            // internal pages
35
            if (sub.length > 0) {
Laurent Heirendt's avatar
Laurent Heirendt committed
36
37
38
                UrlExists(internalURL+'/stable/internal/'+sub, function(status){
                    if (status == 200) { // if sub-card is internal in the internal directory and exists
                        window.location.href = internalURL+'/stable/internal/'+sub;
Laurent Heirendt's avatar
fix bug    
Laurent Heirendt committed
39
                    } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
40
41
42
43
                        UrlExists(internalURL+'/stable/external/'+sub, function(status){
                            if (status == 200) { // if sub-card is internal in the external directory and exists
                                window.location.href = internalURL+'/stable/external/'+sub;
                            } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
44
                                window.location.href = internalURL+'/stable/404.html';
Laurent Heirendt's avatar
Laurent Heirendt committed
45
46
                            }
                        });
Laurent Heirendt's avatar
fix bug    
Laurent Heirendt committed
47
                    }
Laurent Heirendt's avatar
add )    
Laurent Heirendt committed
48
                });
49
            } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
50
51
52
53
                UrlExists(internalURL+'/stable', function(status){
                    if (status == 200) { // if card is internal and exists
                        window.location.href = internalURL+'/stable';
                    } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
54
                        window.location.href = internalURL+'/stable/404.html';
Laurent Heirendt's avatar
Laurent Heirendt committed
55
56
                    }
                });
57
            }
Laurent Heirendt's avatar
Laurent Heirendt committed
58
        // external pages
Laurent Heirendt's avatar
Laurent Heirendt committed
59
        } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
60
            if (sub.length > 0) { sub = 'external/'+sub; }
Laurent Heirendt's avatar
Laurent Heirendt committed
61
62
63
64
            UrlExists(externalURL+'/stable/'+sub, function(status){
                if (status == 200) { // if sub-car is internal and exists
                    window.location.href = externalURL+'/stable/'+sub;
                } else {
Laurent Heirendt's avatar
Laurent Heirendt committed
65
                    window.location.href = externalURL+'/stable/404.html';
Laurent Heirendt's avatar
Laurent Heirendt committed
66
67
                }
            });
Laurent Heirendt's avatar
Laurent Heirendt committed
68
69
70
        }
    });
    </script>
Laurent Heirendt's avatar
Laurent Heirendt committed
71
72
73
  </head>
  <body>
    <p>
74
      Please follow to <a href="https://r3.pages.uni.lu/howto-cards/stable">https://r3.pages.uni.lu/howto-cards/stable</a>!
Laurent Heirendt's avatar
Laurent Heirendt committed
75
76
77
    </p>
  </body>
</html>