Viewing 13 replies - 1 through 13 (of 13 total)
  • Well, I’m not sure that I understand but I think that you can create a page (name=pagename and id=123 in this example) and stick some rewrite rules in the end of functions.php, something like this:

    add_rewrite_tag('%example%','([^&]+)');
    add_rewrite_tag('%example2%','([^&]+)');
    
    add_rewrite_rule('^pagename/([^/]*)/([^/]*)/?','index.php?page_id=123&example=$matches[1]&example2=$matches[2]','top');
    Thread Starter Connection Graphics

    (@connectiongraphics)

    I tried it, I think it may be working, usually you would just use
    $_GET[example1] but thats not working, is there something else I would use now to retrieve the variable?

    You can for example install a plugin like Include Me and stick a line in the pagename page [includeme file=”file.php”] and do your $_GET[‘example’] and so on in file.php.

    Thread Starter Connection Graphics

    (@connectiongraphics)

    I did try it in a php file, its working for the ?example=test1 but not for the rewrite, is there something else to use?

    I’m still not sure that I understand. Have you done as I suggested above and included the php file (with $_GET[‘example’] and so on) into the page that you’re redirecting to to be able to retrieve the variables? If so, what does the error_log say?

    Thread Starter Connection Graphics

    (@connectiongraphics)

    If I type the page like this
    https://domainname.com/pagename/?example=test1&example2=test2
    $_GET[example] works.

    https://domainname.com/pagename/test1/test2/

    its actually showing the right page and not a “404 error – page not found” but it isn’t doing the $_GET[example] .. it just shows nothing where it is supposed to be

    Thread Starter Connection Graphics

    (@connectiongraphics)

    is there anything else that might work now?

    That’s why you should include a php script into the WordPress page called pagename to retrieve the variables.

    How did you retrieve the variables before? $_GET[example1] should be $_GET[‘example’] in the above example by the way.

    Thread Starter Connection Graphics

    (@connectiongraphics)

    <?php echo $_GET[example]; ?> is in a php file, and it isn’t working on the rewrite

    Well, have you included that php file in your pagename page (and put ‘example’ in quotation marks)? And what does the error_log say?

    Thread Starter Connection Graphics

    (@connectiongraphics)

    Its not working with the ‘ ‘ or ” ” marks either, but someone on another forum gave me this

    echo $wp_query->query_vars[‘example’];

    and its what I needed for the rewrite, its working. Thank you for the functions page code and the help ??

    No problem, I don’t know what template you’re running but remember to be careful if you’re modifying WordPress default template or core files. You might have to modify that file again when you upgrade so remember what you put in there or your site might break later on.

    Thread Starter Connection Graphics

    (@connectiongraphics)

    Its a page template in a custom theme, it should be fine. Thank you for the help.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘WordPress htaccess rewrite question?’ is closed to new replies.