简体   繁体   中英

Rewrite URL not working in Wordpress

I have a Wordpress site in a subfolder like this: www.example.com/TEST . I want to rewrite a URL for a specific page which is from post_type = page .

For example, I have a page like this: www.example.com/TEST/albama-test

And I need end result URL to be like: www.example.com/TEST/albama-test/blog

How do I achieve this?

I tried to use add_rewrite_rule but it's not working for me.

function custom_rewrite_basic() {
    add_rewrite_rule('^blog/([0-9]+)/?', 'index.php?page_id=1053', 'top');
}
add_action('init', 'custom_rewrite_basic');

Try this code

function custom_rewrite_basic() {
        add_rewrite_rule('albama-test/blog/?(/([^/]+))?/?','index.php?pagename=albama-test','top');
}
add_action('init', 'custom_rewrite_basic');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM