使用301重定向SEO,将所有404错误自动重定向到任何页面。您可以重定向和记录每404个错误。网站管理员工具中不再出现404错误。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

97 lines
5.9 KiB

  1. <?php
  2. // If this file is called directly, abort.
  3. defined( 'ABSPATH' ) or exit; ?>
  4. <form method="post" action="options.php">
  5. <?php settings_fields( 'i4t3_gnrl_options' ); ?>
  6. <?php $options = get_option( 'i4t3_gnrl_options' ); ?>
  7. <?php $cp_style = ( $options['redirect_to'] !== 'page' ) ? 'jj4t3-hide' : '' ?>
  8. <?php $cl_style = ( $options['redirect_to'] !== 'link' ) ? 'jj4t3-hide' : '' ?>
  9. <?php $cl_style = ( ! in_array( $options['redirect_to'], array( 'link', 'page', '0' ) ) ) ? '' : $cl_style; ?>
  10. <table class="form-table">
  11. <tbody>
  12. <?php $statuses = jj4t3_redirect_statuses(); ?>
  13. <?php if ( !empty( $statuses ) ) : ?>
  14. <tr>
  15. <th><?php _e( 'Redirect type', '404-to-301' ); ?></th>
  16. <td>
  17. <select name='i4t3_gnrl_options[redirect_type]'>
  18. <?php foreach ( $statuses as $status => $label ) : ?>
  19. <option value='<?php echo $status; ?>' <?php selected( $options['redirect_type'], $status ); ?>><?php echo $label; ?></option>
  20. <?php endforeach; ?>
  21. </select>
  22. <p class="description jj4t3-p-desc"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e( 'Learn more', '404-to-301' ); ?></strong></a> <?php _e( 'about these redirect types', '404-to-301' ); ?>
  23. </p>
  24. </td>
  25. </tr>
  26. <?php endif; ?>
  27. <tr>
  28. <th><?php _e( 'Redirect to', '404-to-301' ); ?></th>
  29. <td>
  30. <select name='i4t3_gnrl_options[redirect_to]' id='jj4t3_redirect_to'>
  31. <option value='page' <?php selected( $options['redirect_to'], 'page' ); ?>><?php _e( 'Existing Page', '404-to-301' ); ?></option>
  32. <option value='link' <?php selected( $options['redirect_to'], 'link' ); ?>><?php _e( 'Custom URL', '404-to-301' ); ?></option>
  33. <option value='0' <?php selected( $options['redirect_to'], 0 ); ?>><?php _e( 'No Redirect', '404-to-301' ); ?></option>
  34. </select>
  35. <p class="description jj4t3-p-desc"><strong><?php _e( 'Existing Page', '404-to-301' ); ?>:</strong> <?php _e( 'Select any WordPress page as a 404 page', '404-to-301' ); ?>.</p>
  36. <p class="description jj4t3-p-desc"><strong><?php _e( 'Custom URL', '404-to-301' ); ?>:</strong> <?php _e( 'Redirect 404 requests to a specific URL', '404-to-301' ); ?>.</p>
  37. <p class="description jj4t3-p-desc"><strong><?php _e( 'No Redirect', '404-to-301' ); ?>:</strong> <?php _e( 'To disable redirect', '404-to-301' ); ?>.</p>
  38. <p class="description jj4t3-p-desc"><strong><?php _e( 'You can override this by setting individual custom redirects from error logs list.', '404-to-301' ); ?></strong></p>
  39. </td>
  40. </tr>
  41. <tr id="custom_page" class="<?php echo $cp_style; ?>">
  42. <th><?php _e( 'Select the page', '404-to-301' ); ?></th>
  43. <td>
  44. <?php wp_dropdown_pages( array( 'name' => 'i4t3_gnrl_options[redirect_page]', 'selected' => $options['redirect_page'] ) ); ?>
  45. <p class="description jj4t3-p-desc"><?php _e( 'The default 404 page will be replaced by the page you choose in this list.', '404-to-301' ); ?></p>
  46. <p class="description jj4t3-p-desc"><?php printf( __( 'You can <a href="%s" target="_blank">create a custom 404</a> page and assign that page here.', '404-to-301' ), admin_url( 'post-new.php?post_type=page' ) ); ?></p>
  47. </td>
  48. </tr>
  49. <tr id="custom_url" class="<?php echo $cl_style; ?>">
  50. <th><?php _e( 'Custom URL', '404-to-301' ); ?></th>
  51. <td>
  52. <input type="url" size="40" placeholder="<?php echo home_url(); ?>" name="i4t3_gnrl_options[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
  53. <p class="description jj4t3-p-desc"><?php _e( 'Enter any url (including http://)', '404-to-301' ); ?></p>
  54. </td>
  55. </tr>
  56. <tr>
  57. <th><?php _e( 'Log 404 Errors', '404-to-301' ); ?></th>
  58. <td>
  59. <input type="checkbox" name="i4t3_gnrl_options[redirect_log]" value="1" <?php checked( jj4t3_get_option( 'redirect_log' ), 1 ); ?> />
  60. <p class="description jj4t3-p-desc"><?php _e( 'Enable/Disable Logging', '404-to-301' ); ?></p>
  61. </td>
  62. </tr>
  63. <tr>
  64. <th><?php _e( 'Email notifications', '404-to-301' ); ?></th>
  65. <td>
  66. <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked( jj4t3_get_option( 'email_notify' ), 1 ); ?> />
  67. <p class="description jj4t3-p-desc"><?php _e( 'If you check this, an email will be sent on every 404 log on the admin email account.', '404-to-301' ); ?></p>
  68. </td>
  69. </tr>
  70. <tr>
  71. <th><?php _e( 'Disable URL guessing', '404-to-301' ); ?></th>
  72. <td>
  73. <input type="checkbox" name="i4t3_gnrl_options[disable_guessing]" value="1" <?php checked( jj4t3_get_option( 'disable_guessing' ), 0 ); ?> />
  74. <p class="description jj4t3-p-desc"><?php printf( __( 'If you disable URL guessing, it will stop WordPress from autocorrecting incorrect URLs. %1$sLearn more%2$s about canonical redirect.', '404-to-301' ), '<a href="https://developer.wordpress.org/reference/functions/redirect_canonical/" target="_blank">', '</a>' ); ?></p>
  75. </td>
  76. </tr>
  77. <tr>
  78. <th><?php _e( 'Email address', '404-to-301' ); ?></th>
  79. <td>
  80. <?php $notify_address = ( isset( $options['email_notify_address'] ) ) ? $options['email_notify_address'] : get_option( 'admin_email' ); ?>
  81. <input type="email" placeholder="<?php echo get_option( 'admin_email' ); ?>" name="i4t3_gnrl_options[email_notify_address]" value="<?php echo $notify_address; ?>">
  82. <p class="description jj4t3-p-desc"><?php _e( 'Change the recipient email address for error log notifications.', '404-to-301' ); ?></p>
  83. </td>
  84. </tr>
  85. <tr>
  86. <th><?php _e( 'Exclude paths', '404-to-301' ); ?></th>
  87. <td>
  88. <textarea rows="5" cols="50" placeholder="wp-content/plugins/abc-plugin/css/" name="i4t3_gnrl_options[exclude_paths]"><?php echo $options['exclude_paths']; ?></textarea>
  89. <p class="description jj4t3-p-desc"><?php _e( 'If you want to exclude few paths from error logs, enter here. One per line.', '404-to-301' ); ?></p>
  90. </td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. <?php submit_button( __( 'Save settings', '404-to-301' ) ); ?>
  95. </form><!-- /.form -->