redirection.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <h3><i class="level up alternate icon"></i> Redirection Rules</h3>
  2. <p>Add exception case for redirecting any matching URLs</p>
  3. <div class="ui basic segment">
  4. <table class="ui very basic celled table">
  5. <thead>
  6. <tr>
  7. <th>Redirection URL</th>
  8. <th>Destination URL</th>
  9. <th>Copy Pathname</th>
  10. <th>Status Code</th>
  11. </tr>
  12. </thead>
  13. <tbody id="redirectionRuleList">
  14. <tr>
  15. <td></td>
  16. <td></td>
  17. <td></td>
  18. <td></td>
  19. </tr>
  20. </tbody>
  21. </table>
  22. </div>
  23. <div class="ui divider"></div>
  24. <p>Add path redirection to your domain</p>
  25. <div class="ui divider"></div>
  26. <div class="ui form">
  27. <div class="field">
  28. <label>Redirection URL</label>
  29. <input type="text" name="redirection-url" placeholder="Redirection URL">
  30. <small><i class="ui circle info icon"></i> Redirection URL, any matching prefix of the request URL will be redirected to the following destination URL.</small>
  31. </div>
  32. <div class="field">
  33. <label>Destination URL</label>
  34. <input type="text" name="destination-url" placeholder="Destination URL">
  35. </div>
  36. <div class="field">
  37. <div class="ui checkbox">
  38. <input type="checkbox" name="forward-childpath" tabindex="0" class="hidden" checked>
  39. <label>Forward Pathname</label>
  40. </div>
  41. <div class="ui message">
  42. <p>Append the current pathname after the redirect destination</p>
  43. <i class="check square outline icon"></i> old.example.com<b>/blog</b> <i class="long arrow alternate right icon" style="margin-left: 1em;"></i> new.example.com<b>/blog</b> <br>
  44. <i class="square outline icon"></i> Disabled old.example.com<b>/blog</b> <i class="long arrow alternate right icon" style="margin-left: 1em;"></i> new.example.com
  45. </div>
  46. </div>
  47. <div class="grouped fields">
  48. <label>Redirection Status Code</label>
  49. <div class="field">
  50. <div class="ui radio checkbox">
  51. <input type="radio" name="redirect-type" value="307" checked>
  52. <label>Temporary Redirect <br><small>Status Code: 307</small></label>
  53. </div>
  54. </div>
  55. <div class="field">
  56. <div class="ui radio checkbox">
  57. <input type="radio" name="redirect-type" value="301">
  58. <label>Moved Permanently <br><small>Status Code: 301</small></label>
  59. </div>
  60. </div>
  61. </div>
  62. <button class="ui button" onclick="addRules();">Add</button>
  63. </div>
  64. <script>
  65. $(".checkbox").checkbox();
  66. function addRules(){
  67. let redirectUrl = document.querySelector('input[name="redirection-url"]').value;
  68. let destUrl = document.querySelector('input[name="destination-url"]').value;
  69. let forwardChildpath = document.querySelector('input[name="forward-childpath"]').checked;
  70. let redirectType = document.querySelector('input[name="redirect-type"]:checked').value;
  71. $.ajax({
  72. url: "/redirect/add",
  73. method: "POST",
  74. data: {
  75. redirectUrl: redirectUrl,
  76. destUrl: destUrl,
  77. forwardChildpath: forwardChildpath,
  78. redirectType: parseInt(redirectType),
  79. },
  80. success: function(data){
  81. alert(data);
  82. }
  83. })
  84. }
  85. function deleteRule(redirectDomain){
  86. }
  87. function initRedirectionRuleList(){
  88. $("#redirectionRuleList").html("");
  89. $.get("/redirect/list", function(data){
  90. console.log(data);
  91. data.forEach(function(entry){
  92. $("#redirectionRuleList").append(`<tr>
  93. <td>${entry.RedirectURL}</td>
  94. <td>${entry.TargetURL}</td>
  95. <td>${entry.ForwardChildpath?"<i class='ui green checkmark icon'></i>":"<i class='ui red remove icon'></i>"}</td>
  96. <td>${entry.StatusCode==307?"Temporary Redirect (307)":"Moved Permanently (301)"}</td>
  97. </tr>`);
  98. });
  99. });
  100. }
  101. initRedirectionRuleList();
  102. </script>