2016-09-14 5 views
1

私はこのことから私のURLをきれいにしたいと思います:.htaccess、どうすればURLからパターンを削除できますか?

https://example.com/track&id=180 

へ:

https://example.com/track/180 

私のコードは次の通りである:

マイ.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 
RewriteRule ^welcome/([^/]+)/?$    index.php?a=welcome&filter=$1 [NC,QSA,L] 
RewriteRule ^track/([^/]+)/?$     index.php?a=track&filter=$1  [NC,QSA,L] 
RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3    [L,QSA] 

しかし、私の場合2番目の例を使用してください(&id=のないURL)Ajax経由で "undefined"を返します。

は、私は私のリクエストで、私は$_GET['id'];としてPHPでidパラメータを取得するので、それは未定義だはず、このリンクボタン

<a href="'.$this->url.'/track/'.$id.'" rel="loadpage">Click Here</a> 

とAjax呼び出しを試してみました。

私の質問は、なぜAjaxで動作しないのですか?ここで

は私functions.js

$(function() { 
    $("body").on("click", "a[rel='loadpage']", function(e) { 
     // Get the link location that was clicked 
     startLoadingBar(); 
     pageurl = $(this).attr('href'); 
     // Replace the path of the url from index to the path with raw content 
     var custom = pageurl; 
     var custom = custom.replace(baseUrl+'/track', 'page.php?a=track'); 
     var custom = custom.replace(baseUrl+'/', 'page.php?a=welcome'); 
     // Request the page 
     $.ajax({url:custom,success: function(data) { 
      // Show the content 
      $('#content').html(data); 
      // Stop the loading bar 
      stopLoadingBar(); 
      // Scroll the document at the top of the page 
      $(document).scrollTop(0); 
      // Reload functions 
      selectExplore(); 
      reload(); 
     }}); 


     // Store the url to the last page accessed 
     if(pageurl != window.location){ 
      window.history.pushState({path:pageurl}, '', pageurl); 
     } 
     return false; 
    }); 
}); 

.htaccessは私の得意ではないので、任意の助けをいただければ幸いです。

ありがとうございます。

+0

問題は、あなただけのAJAXを使用して対のブラウザでそれを置けばアヤックス – NineCattoRules

+0

が書き換えられたURLの作業を行うだけですか? –

+0

@PanamaJackはい、 'https:// example.com/track/180'に直接行くとすべて正常に動作します。 – NineCattoRules

答えて

1

あなたがこれを使用することができますが、あなたのAJAX呼び出しを送信するためのコードをJS:

var custom = pageurl.replace(baseUrl+'/track/', '/page.php?a=track&id='); 

// Request the page 
$.ajax({url:custom,success: function(data) { 
    // ... 
} 
+1

どうもありがとう、私はちょうどあなたがルートフォルダにない場合に 'var custom = pageurl.replace(baseUrl + '/ track /'、 'page.php?a = track​​')を変更しました。 – NineCattoRules

関連する問題