Our companies blog is installed in /blog
. Our permalink structure is /%postname%/
so posts currently look like https://www.domain.com/blog/post
We’ve been asked to publish a series of guides which must be installed in /buying-guides/
e.g. https://www.domain.com/buying-guides/kittens
i.e. outside of the WordPress folder.
I thought the answer was to simply create a page called buying-guides and then create a page per guide as children. We then end up with URLs such as https://www.domain.com/blog/buying-guides/kittens. I then created an .htaccess
rule in our root folder with
RewriteRule ^buying-guides/(.+)$ /blog/$1 [L,NC]
and it seems to be working beautifully! Until I realized that, there is more to it as WordPress is obviously not aware of the rewrite. For example, we use the_permalink()
function to generate the link in our page titles and this now obviously generates the incorrect link (although it would still work, but we don’t want customers too see any mention of /blog/
when browsing the buying guides.
Is there a good solution to the above issue? Perhaps a filter than automatically changes all URLs just before the page is rendered from /blog/buying-guides/
to /buying-guides/
?
Any help would be greatly appreciated!
Have you tried to use
the_permalink()
filter hook?In combination with your current rewrite rule in the .htaccess of your root directory.