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:

    PHP:
    1. // Mod_rewrite stuff
    2. add_action( 'init', 'wpse12708_init' );
    3. function wpse12708_init()
    4. {
    5.     global $wp_rewrite;
    6.     $wp_rewrite->add_external_rule('/review/reference/vocabulary/by-alphabet/([a-zA-Z_]+)/$', 'temp/urlcheck\.php?myvar=$1' );
    7. }
    Which, after flushing the rewrites, puts this into my htaccess file:
    Code (Text):
    1. # BEGIN WordPress
    2. <IfModule mod_rewrite.c>
    3. RewriteEngine On
    4. RewriteBase /
    5. RewriteRule ^index\.php$ - [L]
    6. RewriteRule ^/review/reference/vocabulary/by-alphabet/([a-zA-Z_]+)/$ /temp/urlcheck\.php?myvar=$1 [QSA,L]
    7. RewriteCond %{REQUEST_FILENAME} !-f
    8. RewriteCond %{REQUEST_FILENAME} !-d
    9. RewriteRule . /index.php [L]
    10. </IfModule>
    11.  
    12. # END WordPress
    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:
    1. <?php
    2. define('WP_USE_THEMES', false);
    3. require('../wp-load.php');
    4.  
    5. $currenturl = $_SERVER['REQUEST_URI'];
    6. echo "Current url: $currenturl<br><br>";
    7.  
    8. print_r($_POST);
    9. var_dump($_GET);
    10.  
    11. ?>
    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