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.

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

http://thewhiterabbit.dk/beta/steder-detail/?id=floos

i want it to be like

http://thewhiterabbit.dk/beta/steder-detail/floos

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
add comment

1 Answer

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
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.