title: URL re-writing without affecting ajax functions
body: <p>I am making classifieds ad web site. In that I need to load one ad without URL parameters. I did it with URL parameters successfully. Now I want to remove parameters from the URL. I stored URL-slug which is constructed saving time of ad in database.  In ad page load time there are many functions called. Those functions asks data from database according to URL parameter value. I tried with htaccess rules. But rest of page and details load as before. But ajax functions called data which are supposed to display on div tags not working. They show whole page inside those divs.</p>
  
  <p>I tried following htaccess rules so far.</p>
  
  <pre><code>Options +FollowSymLinks -MultiViews
  # Turn mod_rewrite on
  RewriteEngine On
  RewriteBase /
  
  # To externally redirect /dir/foo.php to /dir/foo
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
  RewriteRule ^ %1 [R,L,NC]
  
  ## To internally redirect /dir/foo to /dir/foo.php
  RewriteCond %{REQUEST_FILENAME}.php -f [NC]
  RewriteRule ^ %{REQUEST_URI}.php [L]
  
  ReWriteRule ^ad/([a-zA-Z0-9-/]+)$ ad.php?url=$1
  ReWriteRule ^ad/([a-zA-Z0-9-/]+)/ ad.php?url=$1
  </code></pre>
  
  <p>Now I will show sample of my function.</p>
  
  <pre><code>  function load_reviews(){
          var id = "&lt;?php echo $ad-&gt;get_ad_id($unique_ad_url) ?&gt;";
          $.ajax({
              url: './middle/review/load_reviews',
              cache:true,
              type: 'GET',
              async: false,
              data:{
                  id: id
              },
              success: function(response){
                  $('#chat_area').html(response);
              },
              error: function (x, e) {
                  if (x.status == 0) {
                      console.log('You are offline!! -  Please Check Your Network.');
                  } else if (x.status == 404) {
                      console.log('Requested URL not found.');
                  } else if (x.status == 500) {
                      console.log('Internal Server Error.');
                  } else if (e == 'parsererror') {
                      console.log('Error. - Parsing JSON Request failed.');
                  } else if (e == 'timeout') {
                      console.log('Request Time out.');
                  } else {
                      console.log('Unknown Error. - ' + x.responseText);
                  }
              }
          });
          return false;
  
      }
  </code></pre>
  
  <p>In the top of ad.php file I include these code lines to grab last part of url and store it in variable.</p>
  
  <pre><code>$url=$_SERVER['REQUEST_URI'];
  //echo $url;
  $unique_ad_url = basename(parse_url($url, PHP_URL_PATH));
  </code></pre>
  
  <p>Likewise in JavaScript functions I passed ad_id to retrieve it to ajax get relevant data for current viewing ad page.</p>
  
  <p>In ad list page I showed ads with their' url. That is done by as below,</p>
  
  <pre><code>&lt;a href="ad/'.$this-&gt;url_slug($ad['AD_URL']).'" class="card all-card"&gt;
  </code></pre>
  
  <p>More => 
  When I see network responses from chrome develop tools it shows infinitely loading same css, js, other external library files and ajax function called responses recursively. Also it added id parameter to end of ajax URLs.</p>
  
  <p>In the top of ad.php file I echo <code>$unique_ad_url</code> to see value. It also shows inside all divs which are supposed to show only retrieved data. As I mentioned above along with whole ad page it shows that echo value.</p>
  
  <p>At the end I want load ajax retrieved values to present on ad page without such problems. And URL is expected to be like,
  <code>http://ads.com/ad/daihatsu-boon-m700s-new-2016-2019-04-05-22-49-04</code> 
  I appreciate your help for this issue.</p>