Need to change buddypress profile url by add_rewrite_rule

It’s a little tricky with Buddypress. They are not using the WordPress way for rewrites. (https://buddypress.org/support/topic/custom-permalink-and-rewrite-rules-for-buddypress/) They are processing the url in their own module. If you have members as the Buddypress members page slug and the rest of the url is not a Buddypress module it will redirect you to 404.

There is a way to fool their url process:

function it_job_rewrite_bp_uri($path) {
  if(strpos($path, 'members/admin/jobs/it-jobs/create')) {
    return 'members/admin/jobs/it-jobs-create';
  }

  return $path;
}
add_filter('bp_uri', 'it_job_rewrite_bp_uri');

The above code is working correctly only if you process the old url correctly. If you don’t want it processed by Buddypress simply return a path which is not a Buddypress url.

tech