Wordpress页面重写

How can I rewrite a Wordpress URL such that, if I have a page A hosted at www.domain.com/A, Wordpress also displays that page for www.domain.com/A/ABC, www.domain.com/A/ABCDEF, etc.? I understand that this probably isn't a good idea in general. I have a very specific use case for this. My testing server runs Ubuntu while the live server runs Windows Server 2003, both sites are on Apache.

What I've tried:

  • Modifying .htaccess directly:

    RewriteRule A/?.* A/

(I attempted to debug why this didn't work by turning on RewriteLog in my Apache server configuration. I found out that all rewrites end up at Wordpress's index.php anyway, so I figured it might be more appropriate to use Wordpress's rewrite tools for this.)

  • Using WP_Rewrite (in functions.php):

    function A_rewrite( $wp_rewrite ) { $wp_rewrite->rules["A/?.*"] = "A/"; return $wp_rewrite->rules; } add_filter('generate_rewrite_rules', 'A_rewrite');

Both of these approaches failed to rewrite the URL, i.e. the request still went to /A/ABCD, yielding a 404.

Would greatly appreciate guidance on what I did wrong with either of these approaches, or a better solution.

For lack of a better solution that works for me, I ended up doing the following in my functions.php:

$original_request = $_SERVER['REQUEST_URI'];
$new_request = preg_replace("/\/A\/?.*\?id\=([A-Za-z0-9]+)$/", "/A/?id=$1", $original_request);

if ($original_request !== $new_request) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://" . $_SERVER['HTTP_HOST'] . $new_request);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    echo $ret;
    die();
}

in the wordpress don't use the any code. go to setting and permalinks click more option you have you cna seleted any option or selecte other option and writed codes which tyep you want to show