Skip to main content
added 1 character in body
Source Link
H21
  • 46
  • 1
  • 7

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar   »   //domain.com/foo/bar


I'm rebuilding a website that is currently in a home-brew CMS. They have a few pages with children, but the parent page URL does not match the children. The parent URLs were changed but the children were never updated.

Expected Structure:
//domain.com/parent/
//domain.com/parent/child

Current Structure:
//domain.com/parentpage/     (changed from /parent/)
//domain.com/parent/child

I could just create a page for each but I'm trying to avoid having empty/unused pages.

What I'm hoping to do is just create //domain.com/parent-child/ and rewrite the URL to match, but I can't get my rules to take priority over an existing rule.

Maybe I'm misunderstanding what rewrites can accomplish?


add_rewrite_rule

Matched Query:

pagename=foobar&page=pagename=foo-bar&page=

My Attempts: I expected somethig like one of these to be my solution, but I've tried a dozen different minor variations without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');
add_rewrite_rule( '(foo)/(bar)', 'index.php?pagename=$matches[1]$matches[2]&page='pagename=$matches[1]-$matches[2]&page=', 'top');

Default rule my page is matching:

add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/?$', 'pagename=$matches[1]&page=$matches[2]''index.php?pagename=$matches[1]&page=$matches[2]')

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar   »   //domain.com/foo/bar


I'm rebuilding a website that is currently in a home-brew CMS. They have a few pages with children, but the parent page URL does not match the children. The parent URLs were changed but the children were never updated.

Expected Structure:
//domain.com/parent/
//domain.com/parent/child

Current Structure:
//domain.com/parentpage/     (changed from /parent/)
//domain.com/parent/child

I could just create a page for each but I'm trying to avoid having empty/unused pages.

What I'm hoping to do is just create //domain.com/parent-child/ and rewrite the URL to match, but I can't get my rules to take priority over an existing rule.

Maybe I'm misunderstanding what rewrites can accomplish?


add_rewrite_rule

Matched Query:

pagename=foobar&page=

My Attempts: I expected somethig like one of these to be my solution, but I've tried a dozen different minor variations without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');
add_rewrite_rule( '(foo)/(bar)', 'index.php?pagename=$matches[1]$matches[2]&page=', 'top');

Default rule my page is matching:

add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/?$', 'pagename=$matches[1]&page=$matches[2]')

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar   »   //domain.com/foo/bar


I'm rebuilding a website that is currently in a home-brew CMS. They have a few pages with children, but the parent page URL does not match the children. The parent URLs were changed but the children were never updated.

Expected Structure:
//domain.com/parent/
//domain.com/parent/child

Current Structure:
//domain.com/parentpage/     (changed from /parent/)
//domain.com/parent/child

I could just create a page for each but I'm trying to avoid having empty/unused pages.

What I'm hoping to do is just create //domain.com/parent-child/ and rewrite the URL to match, but I can't get my rules to take priority over an existing rule.

Maybe I'm misunderstanding what rewrites can accomplish?


add_rewrite_rule

Matched Query:

pagename=foo-bar&page=

My Attempts: I expected somethig like one of these to be my solution, but I've tried a dozen different minor variations without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');
add_rewrite_rule( '(foo)/(bar)', 'index.php?pagename=$matches[1]-$matches[2]&page=', 'top');

Default rule my page is matching:

add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/?$', 'index.php?pagename=$matches[1]&page=$matches[2]')
added 814 characters in body; edited title
Source Link
H21
  • 46
  • 1
  • 7

Custom add_rewrite_rule - Page Slug wfrom "/ add_rewrite_rulefoo-bar/" to "/foo/bar/"

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar   »   //domain.com/foo/bar


I'm rebuilding a website that is currently in a home-brew CMS. They have a few pages with children, but the parent page URL does not match the children. The parent URLs were changed but the children were never updated.

Expected Structure:
//domain.com/parent/
//domain.com/parent/child

Current Structure:
//domain.com/parentpage/     (//domain.com/foo-bar -->changed from //domain.comparent/foo/bar)
//domain.com/parent/child

I could just create a page for each but I'm trying to avoid having empty/unused pages.

What I'm hoping to do is just create //domain.com/parent-child/ and rewrite the URL to match, but I can't get my rules to take priority over an existing rule.

Maybe I'm misunderstanding what rewrites can accomplish?


add_rewrite_rule

IMatched Query:

pagename=foobar&page=

My Attempts: I expected thissomethig like one of these to be my solution, but I've tried everya dozen different minor variation of this rulevariations without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');
add_rewrite_rule( '(foo)/(bar)', 'index.php?pagename=$matches[1]$matches[2]&page=', 'top');

I'm open to other solutions not using add_rewrite_rule.

I could accomplish this by creating a page with the slug "foo" and creating another page as a child of "foo" named "bar" but I'm trying to avoid creating empty pages.Default rule my page is matching:

add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/?$', 'pagename=$matches[1]&page=$matches[2]')

Custom Page Slug w/ add_rewrite_rule

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar --> //domain.com/foo/bar


add_rewrite_rule

I expected this to be my solution, but I've tried every minor variation of this rule without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');

I'm open to other solutions not using add_rewrite_rule.

I could accomplish this by creating a page with the slug "foo" and creating another page as a child of "foo" named "bar" but I'm trying to avoid creating empty pages.

add_rewrite_rule - Page Slug from "/foo-bar/" to "/foo/bar/"

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar   »   //domain.com/foo/bar


I'm rebuilding a website that is currently in a home-brew CMS. They have a few pages with children, but the parent page URL does not match the children. The parent URLs were changed but the children were never updated.

Expected Structure:
//domain.com/parent/
//domain.com/parent/child

Current Structure:
//domain.com/parentpage/     (changed from /parent/)
//domain.com/parent/child

I could just create a page for each but I'm trying to avoid having empty/unused pages.

What I'm hoping to do is just create //domain.com/parent-child/ and rewrite the URL to match, but I can't get my rules to take priority over an existing rule.

Maybe I'm misunderstanding what rewrites can accomplish?


add_rewrite_rule

Matched Query:

pagename=foobar&page=

My Attempts: I expected somethig like one of these to be my solution, but I've tried a dozen different minor variations without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');
add_rewrite_rule( '(foo)/(bar)', 'index.php?pagename=$matches[1]$matches[2]&page=', 'top');

Default rule my page is matching:

add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/?$', 'pagename=$matches[1]&page=$matches[2]')
Source Link
H21
  • 46
  • 1
  • 7

Custom Page Slug w/ add_rewrite_rule

I need foo-bar to become foo/bar instead:

//domain.com/foo-bar --> //domain.com/foo/bar


add_rewrite_rule

I expected this to be my solution, but I've tried every minor variation of this rule without success:

add_rewrite_rule( '^foo/bar', 'index.php?pagename=foo-bar', 'top');

I'm open to other solutions not using add_rewrite_rule.

I could accomplish this by creating a page with the slug "foo" and creating another page as a child of "foo" named "bar" but I'm trying to avoid creating empty pages.