开发者

Extend Wordpress Permalinks to create Virtual Pages and Folders

开发者 https://www.devze.com 2023-02-11 10:54 出处:网络
I am trying to find a way to make Wordpress extend its permalink structure with virtual folders so that they can be used to load dynamic content (ie. from a database) but keeping the WP header and tem

I am trying to find a way to make Wordpress extend its permalink structure with virtual folders so that they can be used to load dynamic content (ie. from a database) but keeping the WP header and template system so the my dynamic content can be placed in the layout.

Example: http://www.mydomain.com/customfolder/product1/

Where customfolder and product1 are not pages or categories present in the Wordpress database. Wordpress normally requires that they are created according to that said structure to work, if not it returns a 404 error.

I wish to use /customfolder/ to extend the permalinks with psuedo/virtual pages. The above link would hence be redirected internally to say products.php?product=$product1&template=style1. This way I can use the url to create a unlimited number of pages that loads dynamic content from a database and defining which template to use for that folder.

It should also be possible to setup different permalink folders to load different files, so that /product/map/ will be redirected to ie. map.php

I have tried both .htaccess and the internal WP_rewrite function without success. I always end up getting 404 errors. I know it's possible to do this through Wordpress and I have seen examples that have been close to what I am trying to do but so far I have not come up with a working solution. Here is the best one so far: http:开发者_如何学JAVA//www.binarymoon.co.uk/2010/02/creating-wordpress-permalink-structure-custom-content/

Any help is appreciated!


@csixty4 I managed to work out a solution that does what I wanted to do, more or less. I have not tried any plugins to create virtual pages. What I did was to setup like .htaccess like this:

RewriteRule ^products/$ /path/mypage.php [L]
RewriteRule ^products/(help|support)[^/]? /path/mypage.php?type=$1 [L]

And then I created the file(s) I needed and called the WP loader and defined that the active theme should not be loaded so that I can output content where I want it.

<?php
define('WP_USE_THEMES', false);
require("/wp-path/wp-blog-header.php");
get_header();
?>

My custom content goes here

<?php
get_footer();
?>

If anyone have any ideas for improvements or suggestions to make this more powerful I would be glad to hear you out.


I'm the author of the Virtual Pages plugin for WordPress. The plugin is still beta for exactly this reason. Some people install my plugin on their site and it works great. Others install it and continue to get 404s on their virtual paths. It's weird. It's unpredictable. It drives me batty.

I'm surprised to hear .htaccess didn't work for you.

Did you try the Simple 301 Redirects plugin? That might also make something like this work.


I recommend Quick Page/Post Redirect Plugin, along with "All In One SEO" the result is excellent.

My config: Wordpress 4.2.1 and Plugin 5.0.6

Check this useful document to use this plugin: Best Way To Set Up Redirects In Your WordPress

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号