WordPress.org

Ready to get started?Download WordPress

Forums

Redirection
Root redirect is created on page creation (11 posts)

  1. t8shter
    Member
    Posted 3 years ago #

    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.

  2. zimbrul
    Member
    Posted 3 years ago #

    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.

  3. t8shter
    Member
    Posted 3 years ago #

    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.

  4. patrickarlt
    Member
    Posted 3 years ago #

    t8shter could you post the fixed code here please I am having the same issue as well Your fix would be greatly appreciated.

  5. t8shter
    Member
    Posted 3 years ago #

    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 );
  6. t8shter
    Member
    Posted 3 years ago #

    sorry, that was the wrong file!

    wp-content/plugins/redirection/models/redirect.php

  7. Gavin
    Member
    Posted 3 years ago #

    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;
            }
  8. jmdr
    Member
    Posted 3 years ago #

    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...

  9. DoZ
    Member
    Posted 3 years ago #

    I hope in a fix soon!
    This is a problem for me too :(

  10. Geoff White
    Member
    Posted 3 years ago #

    Has anyone heard from the developer on this problem?

  11. DoZ
    Member
    Posted 3 years ago #

    I have noticed it happened when you start writing something new without entering a new title first.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic