• Hi !
    I have a page named “member” that displays informations about members of my site using GET parameter in URL. To do that I made a template page used by my member page.
    For example :
    If my URl is http://mysite.com/member/?member=toto, the page display informations about toto.
    My question is : There is a way to do the same thing but with an URL like http://mysite.com/toto directly ?

    Thank you and have a good day !

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could try rewrite rules in .htaccess there are a number of tutorials online about this. Be careful with this though as WP has its own rewrite rules in place.

    A simple manual way to do it is setup redirects using this plugin:
    https://wordpress.org/plugins/redirection/

    e.g.
    /toto
    301
    /member/?member=toto

    It would end up loading the second url in the address bar and you’d need to do this manually for each member so maybe a bit of a dodgy solution.

    Another out of the box way would be to modify your 404.php file to check if the address is a member’s name then instead of producing a 404 access the post or redirect them on, this isn’t really a great way to go about it though.

    You could try rewrite rules in WP. Try this

    add_filter( 'rewrite_rules_array', function($rules) {
        $new = array();
        $new['member/([^/]+)/?$'] = 'index.php?member=$matches[1]';
    
        return array_merge( $new, $rules );
    } );

    so now you will have urls like http://mysite.com/member/toto

    more info here https://codex.wordpress.org/Plugin_API/Filter_Reference/rewrite_rules_array

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Rewrite URL in page template’ is closed to new replies.