How to get “extended” path info from URL in a plugin

In reply to “Update 1“:

The code worked fine for me. So,

I’m still getting a 404 when I go to “mypage” with anything following
the pagename, like so: http://example.com/mypage/foo.

Because your RegEx pattern is ^category/([^/]+)/?, so the URL you should have visited is http://example.com/category/foo. But then, you shouldn’t use category because that “base” is used for category archive permalinks — unless of course you changed it to something like topics.

So you’d use ^mypage/([^/]+)/? and not ^category/([^/]+)/?.

However, you should know that the rewrite rule would conflict with pages which are children of the mypage page. I.e. If foo is a child of mypage, then mypage/foo would load the mypage page and not the child foo page.

In reply to “Update 2“:

When I go to http://example.com/category/123 I get an error 404.

Because WordPress treats the request/URL as a category archive request, so WordPress tries to load a category with the slug of 123 and when not found, the error 404 is thrown. But the $test (i.e. get_query_var( 'test' )) would actually give you the expected value which is 123 as in the above example URL. 🙂