The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other WordPress Rewrite Rule

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #35019

    First off, let me clarify that
    1. the website I’m building is built on WordPress, so it has it’s own rewrite rules
    2. the client wants the permalinks to be /%postname%/ (which is fine since this is mainly a low-number-page site).

    I have a rewrite rule where[bandname] actually pulls from[bandname] which is where my code sits to determine what to display.

    Right now, the link we give to a certain band to view their profile is[bandname] but the client wants it rewritten to[bandname].

    With WordPress, I am getting a conflict (as I knew I would be) when using the script to rewrite everything after the first .com/ . My rewrite rule will try to grab .com/[postname] as a band name and return my “no bands match your criteria” result.

    Any ideas on how to rewrite just the band links? I thought about rewriting /band/[bandname] after it pulls the information, but that would defeat the purpose since you would still have to visit /band/[bandname] for that rewrite to trigger.

    Heres the rewrite code.

    function add_my_var($public_query_vars) {
    $public_query_vars[] = 'band'; // bandname
    return $public_query_vars;
    add_filter('query_vars', 'add_my_var');

    // building the rewrite rules, for the two parameters
    function do_rewrite() {
    add_rewrite_rule('^band/([A-Za-z0-9-]*)$', 'index.php?pagename=bands&band=$matches[1]','top');
    add_action('init', 'do_rewrite');

    Just adding to my thought process. The bands are all stored in my database, so maybe I could query for the bandname against the &band=[bandname]. If it matches, then proceed to rewrite, else, dont.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Other’ is closed to new topics and replies.