Question

I need to rewrite some wordpress permalinks so that site.ca/anypage/page/anytab rewrites to site.ca/anypage/?pagetab=anytab. I've tried a bunch of rewrites that I think should be working but wordpress is just giving me a 404 on the full typed in URL (rather than the proper querystring'd page).

Here's what I've got so far (using a specific page for testing instead of anypage/page/anytab:

RewriteRule ^community-alumni/conference-services/page/(.*)$ community-alumni/conference-services/?pagetab=$1 [L]

This rewrite is just giving me a 404 error however, I know the Regex, at least is passing because if I change the Rewrite to a R=301,L redirect then the page does redirect to the querystring'd page and pulls up the appropriate content, ie:

RewriteRule ^community-alumni/conference-services/page/(.*)$ community-alumni/conference-services/?pagetab=$1 [R=301,L]

Redirects to community-alumni/conference-services/?pagetab=summer-hotel and pulls in the page content. So I can't see why the rewrite which should be pulling in the same content as the querystring'd URL is pulling a 404 - I have a feeling it has to do with wordpress? In the wordpress .htaccess I have this rewrite after RewriteBase and before RewriteRule ^index\.php$ - [L]

Any help is appreciated. Thanks.

Was it helpful?

Solution

I have a feeling it has to do with wordpress?

It probably is, and I'm sure there's some internal to wordpress way of handling it using their rewrite API and (probably) the post_rewrite_rules hook. (More info at the wordpress stack exchange.

But if that doesn't work, you can always try the P flag to internally proxy the request so that the REQUEST_URI that wordpress' controller sees is the one without all the stuff after the /page/ (which is most likely what is causing wordpress to puke).

RewriteRule ^community-alumni/conference-services/page/(.*)$ /community-alumni/conference-services/?pagetab=$1 [L,P]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top