WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i need help in httaccess rewrite of a wordpress site. i have url like below


i want it to be like


i have developed using id=floos, now instead of redeveloping all thing i just want a rule to change the url

any help will be greatly appriciated thanks.

share|improve this question
yes i am using custom permalinks – Lucky Ali Mar 7 '13 at 7:46
/%postname%/ this is i have in cutom structure field – Lucky Ali Mar 7 '13 at 7:48
up vote 2 down vote accepted

At first, you shouldn't use .htaccess directly when working with WordPress. WordPress has powerful rewrite API allowing you to do the stuff from plugins or theme's functions.php

If you need the id=floos on more than one page, consider using rewrite endpoints:

function makeplugins_add_json_endpoint() {
    add_rewrite_endpoint( 'floos', EP_PAGES );
add_action( 'init', 'makeplugins_add_json_endpoint' );

To determinate, whether floos is set up, you check like this:

global $wp_query
if ( is_page() && isset( $wp_query->query_vars['json'] )  ) { ... }

If you need that only for a specific page and the "id" value can change, you'll have to use standard wp_rewrite stuff:

add_filter( 'query_vars', 'binda_query_vars' );
function binda_query_vars( $vars ) {
    $vars[] = 'id';
    return $vars;

add_action( 'generate_rewrite_rules', 'binda_rewrite_rules' );
function binda_rewrite_rules( $wp_rewrite )
    $page = get_post( array( 'post_type' => 'page', 'name' => 'steder-detail' );
    $wp_rewrite->rules = array(
        'steder-detail/(.*)/?$' => $wp_rewrite->index . 'page_id=' . $page->ID . '&id=' . $wp_rewrite->preg_index( 1 ),
    ) + $wp_rewrite->rules;

The value of ID would be accessible as follows:

get_query_var( 'ID' );

PS: Both codes should go either to functions.php, or better to site-specific plugin.

share|improve this answer
thanks for detail reply. but it doesn't seem to work. – Lucky Ali Mar 7 '13 at 9:29
i used standered wp_rewrite dev.evsoft.pk/rabbit_um/steder-detail/floss takes me to home page – Lucky Ali Mar 7 '13 at 9:30
I guess the problem part would be $page = get_page_by_path( 'steder-detail' ); Try to change it to $page = get_post( array( 'post_type' => 'page', 'name' => 'steder-detail' ); or hardcode $page_id = 14 //whatever your ID of steder-detail page is and use $page_id in wp_rewrite rule instead of $page->ID – david.binda Mar 7 '13 at 9:35
your answer helpd . i used code below and worked some how. add_filter( 'query_vars', 'binda_query_vars' ); function binda_query_vars( $vars ) { $vars[] = 'std'; return $vars; } add_action( 'generate_rewrite_rules', 'binda_rewrite_rules' ); function binda_rewrite_rules( $wp_rewrite ) { $page = get_page_by_path( 'steder-detail' ); $wp_rewrite->rules = array( 'steder-detail/(.*)([^/]+)$' => $wp_rewrite->index . '?page_id=' . $page->ID . '&std=' . $wp_rewrite->preg_index(1), ) + $wp_rewrite->rules; } – Lucky Ali Mar 7 '13 at 10:00

Your Answer


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.