Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter smdanish1

    (@smdanish1)

    Hi I got the issue.
    Strangely, my previous codes which i posted here started working too[Yes the same Code].

    Now i have two solutions for the same problem.
    But earlier one seems more SEO friendly. So i will go with it. ??
    Marking this as resolved .

    Thanks Little Package!!!!

    Thread Starter smdanish1

    (@smdanish1)

    Thanks Little Package for your time and motivation.
    There is some progress with this proble which i am updating here.
    I followed the link which you told.
    I changed my index.php file as

    <?php get_header(); ?>
    <form method = “get” action = “<?php bloginfo(‘url’); ?>/product/”>
    <input type=”text” id=”tags” name=”name1″ placeholder=”enter a product name” >
    <input type=”submit”>
    </form>
    <?php get_footer(); ?>

    I also added this line to product.php file
    <?php header(‘Location: localhost/wordpress/product/’ . $_GET[‘name1’]); ?>

    But it is redirecting me to
    https://localhost/wordpress/localhost/wordpress/product/teddy-bear1

    Please suggest.

    Thread Starter smdanish1

    (@smdanish1)

    Hi, Here is what i am trying to do… I have only three file for this exercise.
    When i enter a product and submit it takes me to the prodct page with this url https://localhost/wordpress/product/?name1=teddy-bear1
    But i am unable to access this page if i type below url directly in the address bar
    https://localhost/wordpress/product/teddy-bear1
    Please help.

    1. index.php

    <?php get_header(); ?>
    <form method = “get” action = “/wordpress/product/”>
    <input type=”text” id=”tags” name=”name1″ placeholder=”enter a product name” >
    <input type=”submit”>
    </form>
    <?php get_footer(); ?>

    2. functions.php

    function add_query_vars($aVars) {
    $aVars[] = “name1”;
    return $aVars;
    }
    add_filter(‘query_vars’, ‘add_query_vars’);

    function add_rewrite_rules($aRules) {
    $aNewRules = array(‘product/([^/]+)’ => ‘index.php?pagename=product&name1=$matches[1]’);
    $aRules = $aNewRules + $aRules;
    return $aRules;
    }
    add_filter(‘rewrite_rules_array’, ‘add_rewrite_rules’);

    3. product.php

    <?php
    /*
    Template Name: product
    */
    ?>
    <?php
    echo ‘Test for url rewriting….’;
    if(isset($wp_query->query_vars[‘name1’])) {
    $sMsdsCat = urldecode($wp_query->query_vars[‘name1’]);
    echo $sMsdsCat;
    }
    ?>

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