• Hi

    Upon activation, my theme is executing the following code:

           //change permalinks to /%postname%/
            global $wp_rewrite; 
    
            //Write the rule
            $wp_rewrite->set_permalink_structure('/%postname%/'); 
    
            //Flush the rules and tell it to write htaccess or IIS
            $wp_rewrite->flush_rules();
    

    This works fine on a *nix web server, updating the rewrite rules in .htaccess but it doesn’t create the rewrite rules for IIS.

    Ok, maybe to do with permissions on the Windows machine?

    Here’s the anomaly, when the permalink is updated from the permalink settings page, the rewrite rules are correctly set in the IIS web.config.

    MY QUESTION IS, with Windows IIS, how come the settings page updates the permalink type without a problem, yet the above code doesn’t (but does on *nix)?

    Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Changing the rewrites should not be in a theme. It makes it so you don’t want to change themes (theme lock-in). Please, if this theme is in the WordPress repository, please report it, as it is violating the Theme Requirements.

    The problem you are seeing could be due to the execution order. Themes are last to load and the activation code could easily be running in the context of the old theme instead of the new one. (another reason this sort of thing doesn’t belong in a theme)

    Thread Starter dewd

    (@dewd)

    Don’t worry, this isn’t anywhere in the open market, neither will it ever be. It’s at the behest of a private client. A theme has been built specifically for their purposes.

    The reason we want the default permalink to be the post name is because WordPress and the theme are deployed to multiple environments and sometimes get reinstalled from scratch. Automating the permalink change just removes a manual process.

    WordPress used to automate this rewrite to .htaccess and web.config on install, defaulting permalinks to post name. It now defaults to post id.

    It is highly unlikely this is to do with the running order, since it’s something which works with the htaccess config file in a *nix environment, but not the web.config file in a Windows environment (my problem).

    P.S. Just to politely clarify, this action does not cause theme lock in. All it does is automates the manual action of changing permalinks under settings. Manually changing permalinks using the default interface, under settings updates the rewrites in either htaccess or web.config as appropriate. It’s a core WordPress process. I just don’t know why it works on Windows with a manual update and not an automated one as documented by WordPress.

    WordPress used to automate this rewrite to .htaccess and web.config on install, defaulting permalinks to post name. It now defaults to post id.

    No, WordPress has always defaulted to post id as the “ugly” permalink. The default “pretty” permalink is the date and post name.
    https://codex.wordpress.org/Using_Permalinks

    Manually changing permalinks using the default interface, under settings updates the rewrites in either htaccess or web.config as appropriate.

    Well, no, the file is only written when it needs to. It’s the internal rewrites that are recomputed.
    You might follow through the code here:
    https://developer.wordpress.org/reference/functions/iis7_save_url_rewrite_rules/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Theme Amending Permalink’ is closed to new replies.