WordPress.org

Support

Support » Plugins and Hacks » [Resolved] How to redirect site.com/category/postname/?lang=xx to site.com/xx/postname?

[Resolved] How to redirect site.com/category/postname/?lang=xx to site.com/xx/postname?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Daniel Bachhuber

    @danielbachhuber

    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.

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

    Regards,
    Jean-Pierre

    Plugin Contributor Daniel Bachhuber

    @danielbachhuber

    I think the PHP approach is best for this situation.

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] How to redirect site.com/category/postname/?lang=xx to site.com/xx/postname?’ is closed to new replies.