Support » Plugins » Hacks » WP Rewrite Rules – post under a parent page

  • Hey guys, would be great if any of you could help…

    I am currently in the process of splitting up my site into two sections – one for ‘productA’ and one for ‘productB’. Each page is placed under one of these, so the URL is always ‘productA/somepage/somesubpage’. A custom menu is shown depending on if we are in A or B.

    The problem occurs when I try to handle blog posts. I do not need to split the posts per product (eg. both ‘blog’ pages show the same posts). I do however need to know which section (A or B) I am in when I click to view a single post… Permalinks removes the ‘productA’ from the URL and just shows the post name in the URL.

    Basically I need every post to be accessed with a query string of ‘productA/%postname%’.

    I have looked into adding rewrite rules but have struggled to get this working. My current code:

    // hook add_rewrite_rules function into rewrite_rules_array
    	add_filter('rewrite_rules_array', 'add_rewrite_rules');
    	function add_rewrite_rules($aRules) {
    		$aNewRules = array('([^/]*)/productA' => 'index.php?domain=productA',
    		'([^/]*)/productB' => 'index.php?domain=productB');
    		$aRules = $aNewRules + $aRules;
    		return $aRules;

    Which allows me to append the correct domain to the end of the link to a post, and I can access this through query_vars, but as I forward to ‘index.php’ I can never see a single post – only a list of them.

    Any help would be greatly appreciated.

  • The topic ‘WP Rewrite Rules – post under a parent page’ is closed to new replies.