Content management system 根目录下的Wordpress自定义帖子类型Permalink

Content management system 根目录下的Wordpress自定义帖子类型Permalink,content-management-system,wordpress,Content Management System,Wordpress,我在我的web服务器的/blog/目录中安装了wordpress,因此wordpress主页位于 我正在为内容管理创建一些自定义帖子类型。我想为“产品”自定义类型的URL是。。。对于“人”自定义类型 现在服务器端很简单。问题是让Wordpress生成(重写)永久链接,使它们位于Wordpress安装/根目录(/home/site/public\u html/blog->)下 我可以通过使用PHP输出缓冲区来搜索-n-replace,从而将字符串“”替换为“”,但这样做很麻烦,会占用更多的RAM。

我在我的web服务器的/blog/目录中安装了wordpress,因此wordpress主页位于

我正在为内容管理创建一些自定义帖子类型。我想为“产品”自定义类型的URL是。。。对于“人”自定义类型

现在服务器端很简单。问题是让Wordpress生成(重写)永久链接,使它们位于Wordpress安装/根目录(/home/site/public\u html/blog->)下

我可以通过使用PHP输出缓冲区来搜索-n-replace,从而将字符串“”替换为“”,但这样做很麻烦,会占用更多的RAM。如果有一个官方的或正确的非黑客方式来做到这一点,我宁愿这样做


有人知道怎么做吗?

如果WordPress同时处理博客以及产品和人物的页面,您可能需要重新考虑您的文件夹结构。您仍然可以将WordPress的大部分保留在原来的位置(blog/子目录),并将其
index.php
.htaccess
文件移动到根目录。看

也就是说,如果您真的不想移动任何东西,那么您需要一个更复杂的编程解决方案。为此,您需要使用。诀窍是使用它的各种功能(
add_rewrite_rule
add_rewrite_tag
,等等)创建一组WordPress可以识别的规则,然后在WordPress根文件夹上方的网站根目录中编写自己的
.htaccess
文件

所以,如果你做了这样的事

<?php
// Set up the higher-level (non-WordPress) rewrite rules
// so that you redirect non-WP requests to your own WP install.
function make_my_redirects () {
    global $wp_rewrite;
    add_rewrite_rule('^product/', '/blog/index.php?post_type=product', 'top');
    add_rewrite_rule('^people/', '/blog/index.php?post_type=people', 'top');

    // Save original values used by mod_rewrite_rules() for reference.
    $wp_home = home_url(); // get the old home
    update_option('home', '/'); // change to what you need
    $wp_index = $wp_rewrite->index;
    $wp_rewrite->index = 'blog/index.php';

    // Then actually call generate the .htaccess file rules as a string.
    $htaccess = $wp_rewrite->mod_rewrite_rules();

    // and write the string outside the WordPress root.
    file_put_contents(
        trailingslashit(dirname(ABSPATH)) . '.htaccess',
        $htaccess,
        FILE_APPEND
    );

    // Don't forget to set the original values back. :)
    $wp_rewrite->index = $wp_index;
    update_option('home', $wp_home);
}
register_activation_hook(__FILE__, 'make_my_redirects');
那么,有可能吗?是的,我想。推荐吗?可能不会只需给WordPress提供自己的目录就更容易了

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^product/ /blog/index.php?post_type=product [QSA,L]
RewriteRule ^people/ /blog/index.php?post_type=people [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>