Safe Redirect Manager - Version 1.4

Version Description

(Oct. 9, 2012) = * Use the '*' wildcard at the end of your match value to configure a wildcard redirect. Use the same symbol at the end of your redirect to value in order to have the matched value be appended to the end of the redirect. Thanks prettyboymp for the pull request * Change default request-matching behavior to be case-insensitive. This can be modified using the 'srm_case_insensitive_redirects' filter. * Include an informational 'X-Safe-Redirect-Manager' header when a redirect occurs. Thanks simonwheatley for the pull request

Download this release

Release Info

Developer danielbachhuber
Plugin Icon 128x128 Safe Redirect Manager
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

languages/safe-redirect-manager.pot ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2012 Safe Redirect Manager
2
+ # This file is distributed under the same license as the Safe Redirect Manager package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Safe Redirect Manager 1.4-working\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/safe-redirect-manager\n"
7
+ "POT-Creation-Date: 2012-10-09 23:02:23+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+
15
+ #: safe-redirect-manager.php:259
16
+ msgid ""
17
+ "Safe Redirect Manager Warning: Possible redirect loops and/or chains have "
18
+ "been created."
19
+ msgstr ""
20
+
21
+ #: safe-redirect-manager.php:266
22
+ msgid ""
23
+ "Safe Redirect Manager Error: You have reached the maximum allowable number "
24
+ "of redirects"
25
+ msgstr ""
26
+
27
+ #: safe-redirect-manager.php:367 safe-redirect-manager.php:370
28
+ msgid "Redirect rule updated."
29
+ msgstr ""
30
+
31
+ #: safe-redirect-manager.php:368
32
+ msgid "Custom field updated."
33
+ msgstr ""
34
+
35
+ #: safe-redirect-manager.php:369
36
+ msgid "Custom field deleted."
37
+ msgstr ""
38
+
39
+ #. translators: %s: date and time of the revision
40
+ #: safe-redirect-manager.php:372
41
+ msgid "Redirect rule restored to revision from %s"
42
+ msgstr ""
43
+
44
+ #: safe-redirect-manager.php:373
45
+ msgid "Redirect rule published."
46
+ msgstr ""
47
+
48
+ #: safe-redirect-manager.php:374
49
+ msgid "Redirect rule saved."
50
+ msgstr ""
51
+
52
+ #: safe-redirect-manager.php:375
53
+ msgid "Redirect rule submitted."
54
+ msgstr ""
55
+
56
+ #: safe-redirect-manager.php:376
57
+ msgid "Redirect rule scheduled for: <strong>%1$s</strong>."
58
+ msgstr ""
59
+
60
+ #. translators: Publish box date format, see http:php.net/date
61
+ #: safe-redirect-manager.php:378
62
+ msgid "M j, Y @ G:i"
63
+ msgstr ""
64
+
65
+ #: safe-redirect-manager.php:379
66
+ msgid "Redirect rule draft updated."
67
+ msgstr ""
68
+
69
+ #: safe-redirect-manager.php:431
70
+ msgid "Redirect To"
71
+ msgstr ""
72
+
73
+ #: safe-redirect-manager.php:432
74
+ msgid "HTTP Status Code"
75
+ msgstr ""
76
+
77
+ #: safe-redirect-manager.php:435
78
+ msgid "Redirect From"
79
+ msgstr ""
80
+
81
+ #: safe-redirect-manager.php:439
82
+ msgid "Date"
83
+ msgstr ""
84
+
85
+ #: safe-redirect-manager.php:491
86
+ msgctxt "post type general name"
87
+ msgid "Safe Redirect Manager"
88
+ msgstr ""
89
+
90
+ #: safe-redirect-manager.php:492
91
+ msgctxt "post type singular name"
92
+ msgid "Redirect"
93
+ msgstr ""
94
+
95
+ #. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
96
+ #. Plugin Name of the plugin/theme
97
+ #: safe-redirect-manager.php:494 safe-redirect-manager.php:497
98
+ #: safe-redirect-manager.php:503
99
+ msgid "Safe Redirect Manager"
100
+ msgstr ""
101
+
102
+ #: safe-redirect-manager.php:495
103
+ msgid "Edit Redirect Rule"
104
+ msgstr ""
105
+
106
+ #: safe-redirect-manager.php:496
107
+ msgid "New Redirect Rule"
108
+ msgstr ""
109
+
110
+ #: safe-redirect-manager.php:498
111
+ msgid "View Redirect Rule"
112
+ msgstr ""
113
+
114
+ #: safe-redirect-manager.php:499
115
+ msgid "Search Redirects"
116
+ msgstr ""
117
+
118
+ #: safe-redirect-manager.php:500
119
+ msgid "No redirect rules found."
120
+ msgstr ""
121
+
122
+ #: safe-redirect-manager.php:501
123
+ msgid "No redirect rules found in trash."
124
+ msgstr ""
125
+
126
+ #: safe-redirect-manager.php:544
127
+ msgid "Redirect Settings"
128
+ msgstr ""
129
+
130
+ #: safe-redirect-manager.php:565
131
+ msgid "Redirect From:"
132
+ msgstr ""
133
+
134
+ #: safe-redirect-manager.php:567
135
+ msgid ""
136
+ "This path should be relative to the root of this WordPress installation (or "
137
+ "the sub-site, if you are running a multi-site). Appending a (*) wildcard "
138
+ "character will match all requests with the base."
139
+ msgstr ""
140
+
141
+ #: safe-redirect-manager.php:571
142
+ msgid "Redirect To:"
143
+ msgstr ""
144
+
145
+ #: safe-redirect-manager.php:573
146
+ msgid ""
147
+ "This can be a URL or a path relative to the root of your website (not your "
148
+ "WordPress installation). Ending with a (*) wildcard character will append "
149
+ "the request match to the redirect."
150
+ msgstr ""
151
+
152
+ #: safe-redirect-manager.php:577
153
+ msgid "HTTP Status Code:"
154
+ msgstr ""
155
+
156
+ #: safe-redirect-manager.php:583
157
+ msgid "If you don't know what this is, leave it as is."
158
+ msgstr ""
159
+
160
+ #. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
161
+ #. Plugin URI of the plugin/theme
162
+ #. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
163
+ #. Author URI of the plugin/theme
164
+ msgid "http://www.10up.com"
165
+ msgstr ""
166
+
167
+ #. Description of the plugin/theme
168
+ msgid "Easily and safely manage HTTP redirects."
169
+ msgstr ""
170
+
171
+ #. Author of the plugin/theme
172
+ msgid "Taylor Lovett (10up LLC), VentureBeat"
173
+ msgstr ""
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: tlovett1, tollmanz, taylorde, 10up, jakemgold, danielbachhuber, VentureBeat
3
  Tags: http redirects, redirect manager, url redirection, safe http redirection
4
  Requires at least: 3.1
5
- Tested up to: 3.4.1
6
- Stable tag: trunk
7
 
8
- Safely and easily manage your websites HTTP redirects.
9
 
10
  == Description ==
11
 
@@ -24,6 +24,11 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
24
 
25
  == Changelog ==
26
 
 
 
 
 
 
27
  = 1.3 =
28
  * safe-redirect-manager.php - Globalize SRM class for use in themes/plugins/scripts. Added create_redirect method to make importing easier.
29
 
2
  Contributors: tlovett1, tollmanz, taylorde, 10up, jakemgold, danielbachhuber, VentureBeat
3
  Tags: http redirects, redirect manager, url redirection, safe http redirection
4
  Requires at least: 3.1
5
+ Tested up to: 3.4.2
6
+ Stable tag: 1.4
7
 
8
+ Safely and easily manage your website's HTTP redirects.
9
 
10
  == Description ==
11
 
24
 
25
  == Changelog ==
26
 
27
+ = 1.4 (Oct. 9, 2012) =
28
+ * Use the '*' wildcard at the end of your match value to configure a wildcard redirect. Use the same symbol at the end of your redirect to value in order to have the matched value be appended to the end of the redirect. Thanks [prettyboymp](https://github.com/prettyboymp) for the pull request
29
+ * Change default request-matching behavior to be case-insensitive. This can be modified using the 'srm_case_insensitive_redirects' filter.
30
+ * Include an informational 'X-Safe-Redirect-Manager' header when a redirect occurs. Thanks [simonwheatley](https://github.com/simonwheatley) for the pull request
31
+
32
  = 1.3 =
33
  * safe-redirect-manager.php - Globalize SRM class for use in themes/plugins/scripts. Added create_redirect method to make importing easier.
34
 
safe-redirect-manager.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Safe Redirect Manager
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
  Author: Taylor Lovett (10up LLC), VentureBeat
7
- Version: 1.3
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
@@ -42,7 +42,7 @@ class SRM_Safe_Redirect_Manager {
42
  private $whitelist_hosts = array();
43
 
44
  public $default_max_redirects = 150;
45
-
46
  /**
47
  * Sets up redirect manager
48
  *
@@ -51,6 +51,7 @@ class SRM_Safe_Redirect_Manager {
51
  * @return object
52
  */
53
  public function __construct() {
 
54
  add_action( 'init', array( $this, 'action_register_post_types' ) );
55
  add_action( 'parse_request', array( $this, 'action_parse_request' ), 0 );
56
  add_action( 'after_theme_setup', array( $this, 'action_load_texthost' ) );
@@ -59,9 +60,8 @@ class SRM_Safe_Redirect_Manager {
59
  add_action( 'manage_' . $this->redirect_post_type . '_posts_custom_column' , array( $this, 'action_custom_redirect_columns' ), 10, 2 );
60
  add_action( 'transition_post_status', array( $this, 'action_transition_post_status' ), 10, 3 );
61
  add_filter( 'post_updated_messages', array( $this, 'filter_redirect_updated_messages' ) );
62
- add_action( 'admin_notices', array( $this, 'action_redirect_chain_alert' ) );
63
  add_filter( 'the_title', array( $this, 'filter_admin_title' ), 100, 2 );
64
- add_action( 'admin_init', array( $this, 'action_admin_init' ) );
65
  add_filter( 'bulk_actions-' . 'edit-redirect_rule', array( $this, 'filter_bulk_actions' ) );
66
  add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
67
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
@@ -274,11 +274,14 @@ class SRM_Safe_Redirect_Manager {
274
  * Returns true if max redirects have been reached
275
  *
276
  * @since 1.0
277
- * @uses apply_filters
278
  * @return bool
279
  */
280
  public function max_redirects_reached() {
281
- $redirects = $this->update_redirect_cache();
 
 
 
282
  $max_redirects = apply_filters( 'srm_max_redirects', $this->default_max_redirects );
283
 
284
  return ( count( $redirects ) >= $max_redirects );
@@ -288,11 +291,13 @@ class SRM_Safe_Redirect_Manager {
288
  * Check for potential redirect loops or chains
289
  *
290
  * @since 1.0
291
- * @uses home_url
292
  * @return boolean
293
  */
294
  public function check_for_possible_redirect_loops() {
295
- $redirects = $this->update_redirect_cache();
 
 
296
 
297
  $current_url = parse_url( home_url() );
298
  $this_host = ( is_array( $current_url ) && ! empty( $current_url['host'] ) ) ? $current_url['host'] : '';
@@ -335,7 +340,7 @@ class SRM_Safe_Redirect_Manager {
335
  * @uses is_admin, get_post_meta
336
  * @return string
337
  */
338
- public function filter_admin_title( $title, $post_id ) {
339
  if ( ! is_admin() || false === ( $redirect = get_post( $post_id ) ) || $redirect->post_type != $this->redirect_post_type )
340
  return $title;
341
 
@@ -559,13 +564,13 @@ class SRM_Safe_Redirect_Manager {
559
  <p>
560
  <label for="srm<?php echo $this->meta_key_redirect_from; ?>"><?php _e( 'Redirect From:', 'safe-redirect-manager' ); ?></label><br />
561
  <input class="widefat" type="text" name="srm<?php echo $this->meta_key_redirect_from; ?>" id="srm<?php echo $this->meta_key_redirect_from; ?>" value="<?php echo esc_attr( $redirect_from ); ?>" /><br />
562
- <em><?php _e( 'This path should be relative to the root of this WordPress installation (or the sub-site, if you are running a multi-site).', 'safe-redirect-manager' ); ?></em>
563
  </p>
564
 
565
  <p>
566
  <label for="srm<?php echo $this->meta_key_redirect_to; ?>"><?php _e( 'Redirect To:', 'safe-redirect-manager' ); ?></label><br />
567
  <input class="widefat" type="text" name="srm<?php echo $this->meta_key_redirect_to; ?>" id="srm<?php echo $this->meta_key_redirect_to; ?>" value="<?php echo esc_attr( $redirect_to ); ?>" /><br />
568
- <em><?php _e( 'This can be a URL or a path relative to the root of your website (not your WordPress installation).', 'safe-redirect-manager'); ?></em>
569
  </p>
570
 
571
  <p>
@@ -587,10 +592,10 @@ class SRM_Safe_Redirect_Manager {
587
  * @uses load_plugin_textdomain, plugin_basename
588
  * @return void
589
  */
590
- public function action_admin_init() {
591
- load_plugin_textdomain( 'safe-redirect-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/localization/' );
592
  }
593
-
594
  /**
595
  * Apply whitelisted hosts to allowed_redirect_hosts filter
596
  *
@@ -599,7 +604,7 @@ class SRM_Safe_Redirect_Manager {
599
  * @return array
600
  */
601
  public function filter_allowed_redirect_hosts( $content ) {
602
-
603
  foreach ( $this->whitelist_hosts as $host ) {
604
  $without_www = preg_replace( '/^www\./i', '', $host );
605
  $with_www = 'www.' . $without_www;
@@ -610,7 +615,7 @@ class SRM_Safe_Redirect_Manager {
610
 
611
  return $content;
612
  }
613
-
614
  /**
615
  * Force update on the redirect cache and return cache
616
  *
@@ -653,20 +658,19 @@ class SRM_Safe_Redirect_Manager {
653
 
654
  return $redirect_cache;
655
  }
656
-
657
  /**
658
  * Check current url against redirects
659
  *
660
  * @since 1.0
661
- * @param object $current_request
662
  * @uses esc_url_raw, wp_safe_redirect, untrailingslashit, get_transient, add_filter
663
  * @return void
664
  */
665
- public function action_parse_request( $current_request ) {
666
-
667
- // get requested path and add a / before it
668
- $requested_path = '/' . ltrim( trim( $current_request->request ), '/' );
669
-
670
  // get redirects from cache or recreate it
671
  if ( false === ( $redirects = get_transient( $this->cache_key_redirects ) ) ) {
672
  $redirects = $this->update_redirect_cache();
@@ -680,10 +684,27 @@ class SRM_Safe_Redirect_Manager {
680
 
681
  $redirect_to = $redirect['redirect_to'];
682
  $status_code = $redirect['status_code'];
 
 
 
 
 
683
 
684
  // check if requested path is the same as the redirect from path
685
- if ( $requested_path == $redirect_from ) {
686
-
 
 
 
 
 
 
 
 
 
 
 
 
687
  // whitelist redirect to host if necessary
688
  $parsed_redirect = parse_url( $redirect_to );
689
  if ( is_array( $parsed_redirect ) && ! empty( $parsed_redirect['host'] ) ) {
@@ -691,6 +712,8 @@ class SRM_Safe_Redirect_Manager {
691
  add_filter( 'allowed_redirect_hosts' , array( $this, 'filter_allowed_redirect_hosts' ) );
692
  }
693
 
 
 
694
  // if we have a valid status code, then redirect with it
695
  if ( in_array( $status_code, $this->valid_status_codes ) )
696
  wp_safe_redirect( esc_url_raw( $redirect_to ), $status_code );
@@ -700,7 +723,7 @@ class SRM_Safe_Redirect_Manager {
700
  }
701
  }
702
  }
703
-
704
  /**
705
  * Sanitize redirect to path
706
  *
@@ -714,17 +737,17 @@ class SRM_Safe_Redirect_Manager {
714
  */
715
  public function sanitize_redirect_to( $path ) {
716
  $path = trim( $path );
717
-
718
  if ( preg_match( '/^www\./i', $path ) )
719
  $path = 'http://' . $path;
720
-
721
  if ( ! preg_match( '/^https?:\/\//i', $path ) )
722
  if ( strpos( $path, '/' ) !== 0 )
723
  $path = '/' . $path;
724
-
725
  return esc_url_raw( $path );
726
  }
727
-
728
  /**
729
  * Sanitize redirect from path
730
  *
@@ -734,22 +757,22 @@ class SRM_Safe_Redirect_Manager {
734
  * @return string
735
  */
736
  public function sanitize_redirect_from( $path ) {
737
-
738
  $path = trim( $path );
739
 
740
  if ( empty( $path ) )
741
- return '';
742
-
743
  // dont accept paths starting with a .
744
  if ( strpos( $path, '.' ) === 0 )
745
  return '';
746
-
747
  // turn path in to absolute
748
  if ( preg_match( '/https?:\/\//i', $path ) )
749
  $path = preg_replace( '/^(http:\/\/|https:\/\/)(www\.)?[^\/?]+\/?(.*)/i', '/$3', $path );
750
  elseif ( strpos( $path, '/' ) !== 0 )
751
  $path = '/' . $path;
752
-
753
  return esc_url_raw( $path );
754
  }
755
  }
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
  Author: Taylor Lovett (10up LLC), VentureBeat
7
+ Version: 1.4
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
42
  private $whitelist_hosts = array();
43
 
44
  public $default_max_redirects = 150;
45
+
46
  /**
47
  * Sets up redirect manager
48
  *
51
  * @return object
52
  */
53
  public function __construct() {
54
+ add_action( 'init', array( $this, 'action_init' ) );
55
  add_action( 'init', array( $this, 'action_register_post_types' ) );
56
  add_action( 'parse_request', array( $this, 'action_parse_request' ), 0 );
57
  add_action( 'after_theme_setup', array( $this, 'action_load_texthost' ) );
60
  add_action( 'manage_' . $this->redirect_post_type . '_posts_custom_column' , array( $this, 'action_custom_redirect_columns' ), 10, 2 );
61
  add_action( 'transition_post_status', array( $this, 'action_transition_post_status' ), 10, 3 );
62
  add_filter( 'post_updated_messages', array( $this, 'filter_redirect_updated_messages' ) );
63
+ add_action( 'admin_notices', array( $this, 'action_redirect_chain_alert' ) );
64
  add_filter( 'the_title', array( $this, 'filter_admin_title' ), 100, 2 );
 
65
  add_filter( 'bulk_actions-' . 'edit-redirect_rule', array( $this, 'filter_bulk_actions' ) );
66
  add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
67
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
274
  * Returns true if max redirects have been reached
275
  *
276
  * @since 1.0
277
+ * @uses apply_filters, get_transient
278
  * @return bool
279
  */
280
  public function max_redirects_reached() {
281
+ if ( false === ( $redirects = get_transient( $this->cache_key_redirects ) ) ) {
282
+ $redirects = $this->update_redirect_cache();
283
+ }
284
+
285
  $max_redirects = apply_filters( 'srm_max_redirects', $this->default_max_redirects );
286
 
287
  return ( count( $redirects ) >= $max_redirects );
291
  * Check for potential redirect loops or chains
292
  *
293
  * @since 1.0
294
+ * @uses home_url, get_transient
295
  * @return boolean
296
  */
297
  public function check_for_possible_redirect_loops() {
298
+ if ( false === ( $redirects = get_transient( $this->cache_key_redirects ) ) ) {
299
+ $redirects = $this->update_redirect_cache();
300
+ }
301
 
302
  $current_url = parse_url( home_url() );
303
  $this_host = ( is_array( $current_url ) && ! empty( $current_url['host'] ) ) ? $current_url['host'] : '';
340
  * @uses is_admin, get_post_meta
341
  * @return string
342
  */
343
+ public function filter_admin_title( $title, $post_id = 0 ) {
344
  if ( ! is_admin() || false === ( $redirect = get_post( $post_id ) ) || $redirect->post_type != $this->redirect_post_type )
345
  return $title;
346
 
564
  <p>
565
  <label for="srm<?php echo $this->meta_key_redirect_from; ?>"><?php _e( 'Redirect From:', 'safe-redirect-manager' ); ?></label><br />
566
  <input class="widefat" type="text" name="srm<?php echo $this->meta_key_redirect_from; ?>" id="srm<?php echo $this->meta_key_redirect_from; ?>" value="<?php echo esc_attr( $redirect_from ); ?>" /><br />
567
+ <p class="description"><?php _e( "This path should be relative to the root of this WordPress installation (or the sub-site, if you are running a multi-site). Appending a (*) wildcard character will match all requests with the base.", 'safe-redirect-manager' ); ?></p>
568
  </p>
569
 
570
  <p>
571
  <label for="srm<?php echo $this->meta_key_redirect_to; ?>"><?php _e( 'Redirect To:', 'safe-redirect-manager' ); ?></label><br />
572
  <input class="widefat" type="text" name="srm<?php echo $this->meta_key_redirect_to; ?>" id="srm<?php echo $this->meta_key_redirect_to; ?>" value="<?php echo esc_attr( $redirect_to ); ?>" /><br />
573
+ <p class="description"><?php _e( "This can be a URL or a path relative to the root of your website (not your WordPress installation). Ending with a (*) wildcard character will append the request match to the redirect.", 'safe-redirect-manager'); ?></p>
574
  </p>
575
 
576
  <p>
592
  * @uses load_plugin_textdomain, plugin_basename
593
  * @return void
594
  */
595
+ public function action_init() {
596
+ load_plugin_textdomain( 'safe-redirect-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
597
  }
598
+
599
  /**
600
  * Apply whitelisted hosts to allowed_redirect_hosts filter
601
  *
604
  * @return array
605
  */
606
  public function filter_allowed_redirect_hosts( $content ) {
607
+
608
  foreach ( $this->whitelist_hosts as $host ) {
609
  $without_www = preg_replace( '/^www\./i', '', $host );
610
  $with_www = 'www.' . $without_www;
615
 
616
  return $content;
617
  }
618
+
619
  /**
620
  * Force update on the redirect cache and return cache
621
  *
658
 
659
  return $redirect_cache;
660
  }
661
+
662
  /**
663
  * Check current url against redirects
664
  *
665
  * @since 1.0
 
666
  * @uses esc_url_raw, wp_safe_redirect, untrailingslashit, get_transient, add_filter
667
  * @return void
668
  */
669
+ public function action_parse_request() {
670
+
671
+ // get requested path and add a / before it
672
+ $requested_path = sanitize_text_field( $_SERVER['REQUEST_URI'] );
673
+
674
  // get redirects from cache or recreate it
675
  if ( false === ( $redirects = get_transient( $this->cache_key_redirects ) ) ) {
676
  $redirects = $this->update_redirect_cache();
684
 
685
  $redirect_to = $redirect['redirect_to'];
686
  $status_code = $redirect['status_code'];
687
+
688
+ if ( apply_filters( 'srm_case_insensitive_redirects', true ) ) {
689
+ $requested_path = strtolower( $requested_path );
690
+ $redirect_from = strtolower( $redirect_from );
691
+ }
692
 
693
  // check if requested path is the same as the redirect from path
694
+ $matched_path = ( untrailingslashit( $requested_path ) == $redirect_from );
695
+
696
+ // check if the redirect_from ends in a wildcard
697
+ if ( !$matched_path && (strrpos( $redirect_from, '*' ) == strlen( $redirect_from ) - 1) ) {
698
+ $wildcard_base = substr( $redirect_from, 0, strlen( $redirect_from ) - 1 );
699
+
700
+ // mark as match if requested path matches the base of the redirect from
701
+ $matched_path = (substr( $requested_path, 0, strlen( $wildcard_base ) ) == $wildcard_base);
702
+ if ( (strrpos( $redirect_to, '*' ) == strlen( $redirect_to ) - 1 ) ) {
703
+ $redirect_to = rtrim( $redirect_to, '*' ) . ltrim( substr( $requested_path, strlen( $wildcard_base ) ), '/' );
704
+ }
705
+ }
706
+
707
+ if ( $matched_path ) {
708
  // whitelist redirect to host if necessary
709
  $parsed_redirect = parse_url( $redirect_to );
710
  if ( is_array( $parsed_redirect ) && ! empty( $parsed_redirect['host'] ) ) {
712
  add_filter( 'allowed_redirect_hosts' , array( $this, 'filter_allowed_redirect_hosts' ) );
713
  }
714
 
715
+ header("X-Safe-Redirect-Manager: true");
716
+
717
  // if we have a valid status code, then redirect with it
718
  if ( in_array( $status_code, $this->valid_status_codes ) )
719
  wp_safe_redirect( esc_url_raw( $redirect_to ), $status_code );
723
  }
724
  }
725
  }
726
+
727
  /**
728
  * Sanitize redirect to path
729
  *
737
  */
738
  public function sanitize_redirect_to( $path ) {
739
  $path = trim( $path );
740
+
741
  if ( preg_match( '/^www\./i', $path ) )
742
  $path = 'http://' . $path;
743
+
744
  if ( ! preg_match( '/^https?:\/\//i', $path ) )
745
  if ( strpos( $path, '/' ) !== 0 )
746
  $path = '/' . $path;
747
+
748
  return esc_url_raw( $path );
749
  }
750
+
751
  /**
752
  * Sanitize redirect from path
753
  *
757
  * @return string
758
  */
759
  public function sanitize_redirect_from( $path ) {
760
+
761
  $path = trim( $path );
762
 
763
  if ( empty( $path ) )
764
+ return '';
765
+
766
  // dont accept paths starting with a .
767
  if ( strpos( $path, '.' ) === 0 )
768
  return '';
769
+
770
  // turn path in to absolute
771
  if ( preg_match( '/https?:\/\//i', $path ) )
772
  $path = preg_replace( '/^(http:\/\/|https:\/\/)(www\.)?[^\/?]+\/?(.*)/i', '/$3', $path );
773
  elseif ( strpos( $path, '/' ) !== 0 )
774
  $path = '/' . $path;
775
+
776
  return esc_url_raw( $path );
777
  }
778
  }