Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I correctly send all traffic from:

http://my-domain.com/about/case-studies/clientName/

to

http://my-domain.com/about/case-studies/?clientName=$clientName

(not seen by visitors)

Using mod-rewrite so that when I hit that URL I see the /case-studies/ page in Wordpress (in the database) with "Hello $clientName"?

Do I need to create a custom page file, or can I get by with my Wordpress page in the database?

Thank you!!

share|improve this question
add comment

1 Answer

This can be accomplished with WordPress's internal rewrite system by using add_rewrite_rule and adding a query var.

function wpse47506_rewrites_init(){
    add_rewrite_rule(
        'about/case-studies/([^/]+)/?$',
        'index.php?pagename=about/case-studies&clientname=$matches[1]',
        'top' );
}
add_action( 'init', 'wpse47506_rewrites_init' );

function wpse47506_query_vars( $query_vars ){
    $query_vars[] = 'clientname';
    return $query_vars;
}
add_filter( 'query_vars', 'wpse47506_query_vars' );

This would go in your functions.php file, then visit the permalinks settings page to flush rewrite rules.

You can access the value of the query var in your page template with:

<?php echo 'Hello ' . get_query_var('clientname'); ?>
share|improve this answer
    
Worked like a charm! Thanks Milo! Great job! –  Tony D Mar 31 '12 at 20:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.