In my WordPress blog, I configured permalinks > Category base to “magazine” with links having this format:

http://www.mydomain.com/magazine/news/europe/france

The above link opens the France Category Archive page. For the record:

  • France is a child of Europe
  • Europe is a child of News

My client wants the URL for the France Category Archive page to change and be like this:
http://www.mydomain.com/europe/france/news

The problem is of course that with the second link, WordPress will NOT open the France category archive page but the News category archive page.

I solved the problem by adding the below in my theme‚Äôs functions.php file, hence redirecting “europe/france/news” to the index.php page with the correct querystring of the France Archives Page.

add_action( 'init', 'wpse12065_init' );
function wpse12065_init()
{
    add_rewrite_rule('europe/france/news', 'index.php?category_name=news%2Feurope%2Ffrance', 'top');    
}

I of course then saved the permalinks from wp admin to flush the rules.

It works, but:

  1. Is this a clean solution? How expensive is it in terms of performance?
  2. Can I have 50 rules like this one?
  3. Will this break any plugins?

Read more here: Help with add_rewrite_rule solution


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

,

Wordpress related questions and answers: