我想從這個清理我的網址:.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]
但是,如果我使用第二個示例(沒有&id=
的URL)通過Ajax它返回「未定義」。
我嘗試Ajax調用此鏈接按鈕
<a href="'.$this->url.'/track/'.$id.'" rel="loadpage">Click Here</a>
我認爲這是不確定的,因爲在我的請求,我得到的id
參數在PHP作爲$_GET['id'];
。
所以我的問題是:爲什麼它不適用於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
是不是我的專長,所以任何幫助,將不勝感激。
在此先感謝。
這個問題只與阿賈克斯 – NineCattoRules
請問,如果你只是把它在瀏覽器中重寫URL工作VS用ajax? –
@PanamaJack是的,如果我直接去'https:// example.com/track/180',一切正常。 – NineCattoRules