• Hi wordpresscommunity,

    I’am trying to add a custom URL rewrite to my wordpress-site. When %25% is in located in the url, I want to forward to index.php (dont ask me why ;)). The correct rewrite I stumbled across is:

    add_rewrite_rule('^(.)%25%(.)$','index.php', 'top');

    I red that the url rewrite has to be added as a plugin. My plugin looks like this:

    <?php
    /**
    * Plugin Name: Custom url rewrite
    * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
    * Description: custom url rewrite
    * Version: 1.0
    * Author: Henk
    * Author URI: http://URI_Of_The_Plugin_Author
    * License: GPL2
    */
    function init() {
    add_rewrite_rule('^(.)%25%(.)$','index.php', 'top');}

    It doesn’t do anything after being activated! not even after flushing my url rewrites. What do I do wrong?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need to register a function in the ‘init’ action to call your code.

    add_action( 'init', 'my_custom_url_rewrite') ;
    function my_custom_url_rewrite() {
       add_rewrite_rule('^(.)%25%(.)$','index.php', 'top');}
    }

    Then go into Settings->Permalinks to make WordPress flush its rewrite rules.

    Thread Starter anyone88

    (@anyone88)

    Changed it to:

    add_action( ‘init’, ‘rewrite2’ );
    function rewrite2() {
    add_rewrite_rule(‘^(.)location=%25(.)$’,’index.php’, ‘top’);}

    still doesn’t work 🙁 Any ideas?

    Could be your regex. Something like this would better match what you’re looking for.

    add_rewrite_rule('.*location=%25$', 'index.php', 'top');

    regexpal.com is a handy tool for testing regular expressions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a custom url rewrite rule to wordpress’ is closed to new replies.