WordPress.org

Ready to get started?Download WordPress

Forums

Safe Redirect Manager
[resolved] How to redirect site.com/category/postname/?lang=xx to site.com/xx/postname? (5 posts)

  1. JpFayolle
    Member
    Posted 1 year ago #

    Hello,

    I am migrating my current blog with already 60 posts and 3 languages to a new multiste installation with 3 sites /fr/, /en/ and /es/.

    The current urls are: http://www.example.com/category/postname for the posts in english and http://www.example.com/category/postname/?lang=fr or ?lang=es for the french and spanish posts.

    Is there a way to do the redirection with a regexp, and not entering 180 redirections, so that:
    http://www.example.com/category/postname goes to http://www.example.com/en/postname
    and
    http://www.example.com/category/postname/?lang=fr goes to http://www.example.com/fr/postname
    and
    http://www.example.com/category/postname/?lang=es goes to http://www.example.com/es/postname

    Regards,
    Jean-Pierre

    http://wordpress.org/extend/plugins/safe-redirect-manager/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    You could do something based on the 'lang' param (untested):

    add_action( 'template_redirect', 'dbx_redirect_lang' );
    function dbx_redirect_lang() {
    
    	if ( ! is_single() )
    		return;
    
    	if ( ! empty( $_GET['lang'] ) && in_array( $_GET['lang'], array( 'fr', 'es' ) )
    		wp_safe_redirect( $_GET['lang'] . '/' . get_query_var( 'postname' ) );
    	else
    		wp_safe_redirect( 'en/' . get_query_var( 'postname' ) );
    
    	exit;
    }

    This wouldn't need the plugin at all. You'd want to make sure it only executed for the main site though.

  3. JpFayolle
    Member
    Posted 1 year ago #

    Thanks Daniel but I would not use php modification if possible.
    http://wordpress.org/support/topic/multisite-multilingue-redirection-after-migration

    Regards,
    Jean-Pierre

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    I think the PHP approach is best for this situation.

  5. JpFayolle
    Member
    Posted 1 year ago #

    Hi Daniel,

    Maybe but as a consultant in application quality (look at my blog http://www.qualilogy.com), I tend to minimize customization as much as possible.

    Not that it cannot be done correctly, but to do it correctly in this case means a theme child, a good knowledge not only of PHP but of WP APIs and there is always the risk that a plugin will conflict with your own development. Furthermore, you have to maintain your own code in the future.

    So I believe that this is more effort than it is worth in my case. I have been doing a 301 redirection from all the http://www.example.com/category/postname whichever the ?/lang= parameter, to the english page http://www.example.com/en/postname.
    Not the most precise, but as I updated the internal links (to the correct page according to the language), the redirection is only for the external search.

    I will close this topic.
    Regards,
    Jean-Pierre

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic