我將從example.com/action
到example.com/index.html#action
所有鏈接,然後通過我的骨幹路由器解析。骨幹路由器+重寫規則不觸發與路由「/」
但是,我的新頁面signup/:inviteAuthHash
(例如signup/9d519a2005b3dac8802d8e9e416239a1
)不工作;唯一呈現的是我的index.html
,並且我的路由器中沒有任何斷點符合要求。
的.htaccess:
# not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# example.com/home => example.com/index.html#home
RewriteRule ^(.+)$ index.html#$1 [L,QSA]
router.js
var AppRouter = Backbone.Router.extend({
routes : {
/* PAGES */
// beta
'request_invite' : 'request_invite',
'signup/:inviteAuthHash' : 'signup',
// Default
'*actions' : 'defaultAction'
},
/* PAGES */
// eta
request_invite : function() {
new BetaLayout;
new RequestInviteView;
},
signup : function(inviteAuthHash) {
// validate auth hash
if(!InviteRequest.isValidInviteAuthHash(inviteAuthHash))
return this.defaultAction();
else {
new BetaLayout;
new SignupView(SignupView);
}
},
// Default
defaultAction : function(actions) {
app_router.navigate('request_invite');
this.request_invite();
}
});
var initialize = function() {
app_router = new AppRouter;
$('a').live('click', function() {
var href = $(this).attr('href');
// only navigate to real links
if(href == undefined)
return;
// open in new window?
if($(this).prop('target') == '_blank')
return true;
app_router.navigate(href, {trigger: true});
return false;
});
Backbone.history.start({pushState: true});
};
return {
initialize : initialize
};
我的mod_rewrite是有點生疏,但不'RewriteRule'實際發送301或303返回給瀏覽器或者是內部重定向? –
@Garrett我想'註冊/ 9d519a2005b3dac8802d8e9e416239a1'將轉化到URL'的index.html /#signupindex.html /#9d519a2005b3dac8802d8e9e416239a1'因爲兩個'/','/'。我可能也是錯的。另一個疑問是你的邀請哈希包含字符':'?那麼這將不起作用 – Deeptechtons
@ muistooshort - 這取決於您是否使用[R]標誌。如果沒有,那麼它透明地通過隧道(客戶端收到200)。 –