1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using a RewriteRule in Wordpress (It's set up, just not working).

Discussion in 'Apache' started by Submerged, Feb 21, 2012.

  1. #1
    Hey guys,

    I've been pulling my hair out over this all night. My goal is to change this:

    /review/reference/vocabulary/by-alphabet/a/
    into (for now, as a test)
    /temp/urlcheck.php?myvar=a

    where "a" could be any letter or word.

    So far, I've learned to put this into my functions page:

    // Mod_rewrite stuff
    add_action( 'init', 'wpse12708_init' );
    function wpse12708_init()
    {
        global $wp_rewrite;
        $wp_rewrite->add_external_rule('/review/reference/vocabulary/by-alphabet/([a-zA-Z_]+)/$', 'temp/urlcheck\.php?myvar=$1' );
    }
    PHP:
    Which, after flushing the rewrites, puts this into my htaccess file:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^/review/reference/vocabulary/by-alphabet/([a-zA-Z_]+)/$ /temp/urlcheck\.php?myvar=$1 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    Code (markup):
    I also tried it without escaping the period of "urlcheck.php", with no change. When I load up the URL:

    /review/reference/vocabulary/by-alphabet/a/

    It actually redirects to the post with the lowest id (/textbook/introduction/a-brief-history-of-greek/). I have no idea of where to look next. I don't think there are any plugins messing around with it, as I disabled all of my plugins, and still no luck.

    The "urlcheck.php" page is simple, just to test this (I tested this, it's working fine):
    <?php
    define('WP_USE_THEMES', false);
    require('../wp-load.php');
    
    $currenturl = $_SERVER['REQUEST_URI'];
    echo "Current url: $currenturl<br><br>";
    
    print_r($_POST);
    var_dump($_GET);
    
    ?>
    PHP:
    Any help would be amazing. I don't know what I'm doing with Apache :(.
    Thanks!

    P.S. As a side note, I did try a much simpler rewrite (/google.html -> google.com, to paraphrase it), and that worked just fine, so that shouldn't be the issue :).
     
    Last edited: Feb 21, 2012
    Submerged, Feb 21, 2012 IP