Would like to know how it is possible to rewrite www.site.com/?lang=de to www.site.com/de in wordpress using the htaccess rewrite or the wp rewri开发者_运维技巧te. The code can be added into the wordpress files or into the .htaccess file
Here's a way to accomplish this within WordPress:
function stack7478067_init() { // Let ?lang= pass through to WP_Query add_rewrite_tag( '%lang%', '([A-Za-z]+)' ); } add_action( 'init', 'stack7478067_init' ); function stack7478067_pre_get_posts( $query ) { if ( 'de' == $query->get('lang') ) { // if lang=de, redirect die( wp_redirect( site_url( 'de/' ) ) ); } } add_filter( 'pre_get_posts', 'stack7478067_pre_get_posts' );
精彩评论