.htacesss
RewriteCond %{REQUEST_URI} ^/api/(.+)$
RewriteRule ^api/(.+)$ /index.php?api=%1 [QSA,L]
example ajax url request:
'http://hostname.com/api/ext/list.php?query=de'
I want to be able to redirect urls in this format to the following
index.php?api={requested_filename}¶m1=value1¶m2=value2 ...
because the whole site is processed through a bootstrap process in index.php which has a routing part loading configs, templates etc...
When I try a jquery code for example, the POST data is lost after redirect.
$.ajax({
url: '/api/contact.php',
type: 'POST',
data: {
email: $("#contactEmail").val(),
name: $("#contactName").val(),
message: $("#contactMessage").val()
// etc ...
}
});
I've read that you cannot preserve data on a http redirect. But how do all the frameworks avoid that? I've coded in many, and every one is bootstraped through the index.php and there are rewrite rules in the .htaccess file for enabling pretty urls. So in Yii for example, I would call an url "api/uploads/latests.json" with some POST data and the controllers on the backend would receive that data. What am i missing here?
note: I've tested the [P] mod_rewrite parameter, and i think that this server doesn't have mod_proxy enabled.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…