New answers tagged


Are you sure you have correct regex? Also you shouldn't use flush_rewrite_rules() on init hook. Better to just go and re-save permalinks options in admin, so you won't flush rules every time. Try to change regex to all chars, otherwise it looks good. add_rewrite_rule ('^([^/]*)/?', 'index.php?lang=$matches[1]', 'top');


Any rule that doesn't point to index.php is interpreted as an external rule and gets added to .htaccess. $matches array works only when second argument ($redirect) of add_rewrite_rule() point to file index.php. External rules need to use the $1, $2 instead of $matches[1], $matches[2]. Remember to flush rewrite rules after the change.

Top 50 recent answers are included