title: php Ajax - Pretty URL for Dependent Dropdown search result with .htaccess
body: <p>It takes me a few paragraphs to explain this problem. I apologize for any inconvenience this may have caused you. I tried hard and researched a lot to solve the following problems, but so far I couldn't find solutions. </p>
  
  <p>I am working on a directory creation project (using php, mysql, ajax and jquery) and currently I am stuck due to .htaccess URL rewrite issue (url rewrite / pretty url). I am using dependent dropdown on the home page for the search.  The first dropdown is created using php and mysql and the dependent dropdown is created based on the selection on first dropdown using mysql, jquery and ajax. For example if, I select the country in the first dropdown then the related states get listed in the dependent dropdown. Then, once I hit the search button (in index.php page) it goes to the search result page (search.php).  </p>
  
  <p>Also, I have the same search dependent dropdown code on the top of the search.php file, so the users are able to search when they are in this page.  Each of the results on the search.php page has links to go to moreinfroamtion.php where users can see more information about the selected item.  I have placed the same search dependent dropdown code on the top of the moreinfroamtion.php file, so the users are able to search when they are in this page and if they make such searches, then the y are going to see the results in search.php page.</p>
  
  <p>I am using GET method in the form and everything was working fine before implementing the url rewrite/pretty url process through .htaccess file.  Once I upload the .htaccess file with url rewrite/pretty url code in it, everything works fine when I do the dependent dropdown search in index.php file (URL gets rewrite in search.php page <em>From:</em> <strong><em>exampletesting.com/TopTwo/search.php?country=Usa&amp;state=New+York</em></strong> <em>To:</em> <strong><em>exampletesting.com/TopTwo/Jobs/Usa/New+York</em></strong>).  </p>
  
  <p>However, the issue is when I do a dependent dropdown search from this page (exampletesting/TopTwo/jobs/Usa/New+York) it gives the correct database results but displaying the following url on the address bar: 
  <strong><em><a href="http://exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&amp;state=New+York" rel="nofollow">http://exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&amp;state=New+York</a></em></strong> (<em>added the extra ?country=Usa&amp;state=New+York to the end of url</em>).</p>
  
  <p>Also, when I click the link on a result on the result page for more information it brings me the following page without displaying any database results on the page: 
  <strong><em><a href="http://exampletesting.com/TopTwo/Jobs/Driver/moreinfroamtion.php?description=Uber" rel="nofollow">http://exampletesting.com/TopTwo/Jobs/Driver/moreinfroamtion.php?description=Uber</a></em></strong></p>
  
  <p>I tried to place multiple rules in the same .htaccess to rewrite url/pretty url for the moreinformation.php file, but that didn't work. I also perform dependent dropdown search from this page (<strong><em>exampletesting.com/TopTwo/Jobs/Driver/moreinfroamtion.php?description=Uber</em></strong>) and it gives the database results but displaying the following url on the address bar: 
  <strong><em>exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&amp;state=New+York</em></strong> (<em>added the extra ?country=Usa&amp;state=New+York to the url</em>). </p>
  
  <p>I would really appreciate if you guys can help me to resolve the above issues.  </p>
  
  <p><strong>Following is my .htaccess file.</strong></p>
  
  <pre><code>RewriteEngine On
  RewriteBase /TestTwo/
  
  RewriteCond %{THE_REQUEST} /search\.php\?country=([^&amp;]+)&amp;state=([^\s&amp;]+) [NC]
  RewriteRule ^ jobs/%1/%2? [R=301,L]
  
  RewriteRule ^jobs/([^/]+)/([^/]+)/?$ search.php?country=$1&amp;state=$2  [QSA,L,NC]
  </code></pre>
  
  <p><strong>Following is the jquery/ajax code:</strong>         </p>
  
  <pre><code>$(document).ready(function()
  {
      $("#category").change(function()
      {
      var id=$(this).val();
      var data = 'id='+ id;
  
      $.ajax
      ({
      type: "POST",
      url: "http://exampletesting.com/TestTwo/states.php",
      data: data,
      cache: false,
      success: function(html)
     {
        $("#states").html(html);
     } 
     });
    });
  
  });
  </code></pre>