[Plugin: Redirection] Root redirect is created on page creation
-
When I create a new page, a redirect is created for url “/”. So, after I create a new page, if you attempt to browse to my home page, it redirects to the latest page that I just created instead of the static home page.
I can fix this by deleting the redirect in wp-admin or in mysql, but it is very problematic. I’d like to know if this problem is going to be fixed in a newer version of Redirection.
-
That’s true, it does happen to me as well and I think is a bug.
There is a fix on Forums but I think is out dated as the code of the plugin has changed since the fix has been posted.Yeah, any of the posts that I found with a solution weren’t helpful. We edited models/redirect.php so that it wouldn’t create a redirect for URL: / no matter what. That fixed our issue for now, but hopefully the author of the plugin will release an update soon with a permanent fix.
t8shter could you post the fixed code here please I am having the same issue as well Your fix would be greatly appreciated.
I don’t remember what the original file looked like, but if you open wp-content/plugins/redirection/redirect.php and go down to around line 198 or so, you will see a Red_Item::sanitize line … we added that to the $url variable and put in the if below that … hope this helps a little.
$url = Red_Item::sanitize_url( $details['source'], $regex); // preg_match check added to prevent / from being redirected. if ( $group_id > 0 && $matcher && !preg_match('/^\/$/', $url) ) { $regex = ( isset( $details['regex']) && $details['regex'] != false) ? true : false; $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id ) ); $action = $details['red_action']; $action_code = 0; if ( $action == 'url' || $action == 'random' ) $action_code = 301; elseif ( $action == 'error' ) $action_code = 404; if ( isset( $details['action_code'] ) ) $action_code = intval( $details['action_code'] ); $data = array( 'url' => $url, 'action_type' => $details['red_action'], 'regex' => $regex, 'position' => $position, 'match_type' => $details['match'], 'action_data' => $matcher->data( $details ), 'action_code' => $action_code, 'last_access' => 0, 'group_id' => $group_id ); $wpdb->insert( $wpdb->prefix.'redirection_items', $data );
sorry, that was the wrong file!
wp-content/plugins/redirection/models/redirect.php
Thanks for the tips guys.
I was having this problem today, all the new blog posts were automaticallly creating a redirect from /blog/ to the post. SO, the homepage couldn’t be viewed.
Using T8shter’s tip, this is what I did for a plugin hack (look for ‘I ADDED THIS’):
function create( $details ) { global $wpdb; // Auto generate URLs if ( $details['source'] == '' ) $details['source'] = Red_Item::auto_generate(); if ( $details['target'] == '' ) $details['target'] = Red_Item::auto_generate(); // Make sure we don't redirect to ourself if ( $details['source'] == $details['target'] ) $details['target'] .= '-1'; $matcher = Red_Match::create( $details['match'] ); $group_id = intval( $details['group'] ); if ( $group_id > 0 && $matcher ) { $regex = ( isset( $details['regex']) && $details['regex'] != false) ? true : false; $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id ) ); $action = $details['red_action']; $action_code = 0; if ( $action == 'url' || $action == 'random' ) $action_code = 301; elseif ( $action == 'error' ) $action_code = 404; if ( isset( $details['action_code'] ) ) $action_code = intval( $details['action_code'] ); $data = array( 'url' => Red_Item::sanitize_url( $details['source'], $regex), 'action_type' => $details['red_action'], 'regex' => $regex, 'position' => $position, 'match_type' => $details['match'], 'action_data' => $matcher->data( $details ), 'action_code' => $action_code, 'last_access' => 0, 'group_id' => $group_id ); if (!in_array(strtolower($data['url']), array('/','/blog/'))) # I ADDED THIS LINE $wpdb->insert( $wpdb->prefix.'redirection_items', $data ); $group = Red_Group::get( $group_id ); Red_Module::flush( $group->module_id ); return Red_Item::get_by_id( $wpdb->insert_id ); } return false; }
I’ve had this problem for a couple weeks too. Adding the one line as per gavinengel’s hack seems to have fixed it. I hope the plugin author updates this soon…
I hope in a fix soon!
This is a problem for me too 🙁Has anyone heard from the developer on this problem?
I have noticed it happened when you start writing something new without entering a new title first.
- The topic ‘[Plugin: Redirection] Root redirect is created on page creation’ is closed to new replies.