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 have noticed that in some instances in WordPress (such as in my custom post types), GET variables appear as following in the URL:

www.url.com/events/cool-event?action=edit&message=1

However, in other instances (such as when I am pointing to my login 'virtual' page which I created using the rewrite API), the urls look like this:

www.url.com/login/?action=login

As you can see, there is a forward slash before the first variable. What is causing this? Which one is the normal way for them to appear? Is there any functional difference? And finally, assuming that it makes sense, how can I make them both behave in a similar manner?

  • William

Update

add_action( 'init', 'add_virtual_page_template' );
function add_virtual_page_template()
{
    global $wp, $wp_rewrite;

    $wp->add_query_var( 'template' );

    add_rewrite_endpoint( 'login', EP_PERMALINK | EP_PAGES );
    add_rewrite_rule( 'login/?', 'index.php?template=login', 'top' );

    $wp_rewrite->flush_rules();
}

add_action( 'template_redirect', 'add_virtual_page_redirect' );

function add_virtual_page_redirect()
{
    global $wp;

    $queryvar = get_query_var('template');

    if ($queryvar && $queryvar == 'login')
    {
        include(site_url('wp-login.php'));
        exit;
    }
}
share|improve this question
add comment

1 Answer 1

There is no "normal" way (either is commonplace), but it all comes down to your permalink structure, and whether that has a trailing slash or not.

As for your login page, it all depends on how you're generating the URLs, but I would suggest using user_trailingslashit( $basepath_without_query ).

As the name suggests, it will apply (or remove) trailing slashes to match the configured permalink structure.

share|improve this answer
    
Hey - I have included that snippet that I use to generate the URL - how would I implement your solution? –  William Jun 25 '13 at 17:04
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.