• Ok so, my case goes like this – I’ve got 2 simple dropdowns in a html page i created and embedded into one of my wordpress pages.. every time u select something out of the dropboxes it sends a simple AJAX request (through xmlhttp.open) and requests getResults.php with 2 $_GET[] variables (first and second dropdown values).

    getResults.php returns some kind of table within the same page and all this process works just fine.

    my question is – what should i do in case i want to run a google adwords campaign to this specific page but also send these two get variables within the url itself.. i mean, is there any way i could make some url rewrites so mydomain.com/helix-tragus will lead to this requested page but formed like mydomain.com/getResults.php?p=helix&q=tragus ?

    thanks in advance.. hope i was clear enough..

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, you can do rewrites, either with .htaccess or the WP Rewrite API. The problem you will run into is how is the rewrite rule to distinguish between the two parameter getResults URLs and normal post slugs with two words?

    You either need a different separator symbol besides a hyphen – or some sort of defining URL term used much like ‘category’ and ‘tag’ are used to distinguish taxonomy term queries from post slug queries. If your URL can be configured like mydomain.com/results/helix-tragus, then rewrites will work.

    You’ll also have a problem rewriting to a ‘p’ query var as that is used by WP for post ids. Don’t use any query vars listed in WordPress Query Vars.

    Thread Starter rikavon

    (@rikavon)

    well, i tried to follow their instructions and i’ve put these lines in my functions.php but it still didn’t work out for some reason

    function custom_rewrite_tag() {
            add_rewrite_tag('%jewel_one%', '([^&]+)');
            add_rewrite_tag('%jewel_two%', '([^&]+)');
       }
     add_action('init', 'custom_rewrite_tag', 10, 0);
    
        function custom_rewrite_rule() {
            add_rewrite_rule('^compare-jewels/([^/]*)/([^/]*)/?','index.php?page_id=1048&jewel_one=$matches[1]&jewel_two=$matches[2]','top');
        }
        add_action('init', 'custom_rewrite_rule', 10, 0);

    and when i try to reach http://www.mydomain.com/compare-jewels/svarovski/jamesallen – i get an 404 page.. and no redirect to the actual page_id=1048 page for some reason..

    Moderator bcworkz

    (@bcworkz)

    Hmm, your code looks OK. I too struggle with rewrites, so that may not be saying much. Did you remember to flush the rewrite rules? IMO it’s easiest to do so by toggling the permalink settings off and on again in admin settings.

    I hope that’s it, I’m otherwise at a loss. If not, I’ll try to come up with some avenue of investigation, or someone else might see the problem. We’ll get this figured out.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘GET-POST variables AJAX’ is closed to new replies.