2017-07-15 74 views
7

對於在火力文檔中的代碼示例,它說,啓動URL重寫,像這樣:火力地堡:通網址帕拉姆在URL重寫

 "hosting": { 
      // Add the "rewrites" section within "hosting" 
      "rewrites": [ { 
      "source": "**", 
      "destination": "/index.html" 
      } ] 
     } 

我該怎麼辦時,我想傳遞的一個參數索引頁面?我想:

 "hosting": { 
      // Add the "rewrites" section within "hosting" 
      "rewrites": [ { 
      "source": "/item/**", 
      "destination": "/item.html?i=$1" 
      } ] 
     } 

但是,這並不做任何事情..

我也曾嘗試下面的答案:

"hosting": { 
    // Add the "rewrites" section within "hosting" 
    "rewrites": [ { 
    "source": "/item/:item", 
    "destination": "/item.html?i=:item" 
    } ] 
} 

但只是返回一個404頁。

+0

@坦率-VAN-puffelen - 我注意到你編輯這個。你有解決方案嗎? (也注意到你在Firebase工作) – JamesG

+2

我不認爲你想要做什麼是可能的(重寫文檔沒有說變量或佔位符)。相反,請查看Firebase的Cloud Functions以將URL重定向到一個函數,您可以在其中編寫代碼以剖析路徑並生成所需的任何響應。 https://firebase.google。com/docs/hosting/functions –

回答

1

我剛收到一封電子郵件,從與follwing火力地堡支持:

更新從火力地堡支持:

你使用的情況下是不可能的火力地堡單獨託管。您還需要使用雲端函數來執行此操作。 Firebase剛剛發佈了一個原生的Firebase託管+功能集成,它可以執行服務器端處理,因此您可以將URL重定向到一個函數,在該函數中您可以編寫代碼來剖析路徑並生成任何您想要的響應。您可以查看我們的文檔以詳細瞭解它。

https://firebase.google.com/docs/hosting/functions

我已經給他們發電子郵件回來看,如果這是將在未來增加,因爲它似乎有點矯枉過正運行流程,一個頁面的東西。

更新28/07/2017

由於這是不支持的,我已經申請了你一個功能請求。但是,我現在無法分享任何細節或時間表。我們會繼續考慮您的反饋意見。

與此同時,您可以留意我們的發佈說明。

祝您有美好的一天。

https://firebase.google.com/support/releases

-1
"hosting": { 
     // Add the "rewrites" section within "hosting" 
     "rewrites": [ { 
     "source": "/item/:item", 
     "destination": "/item.html?i=:item" 
     } ] 
    } 

試試看。

+0

這將返回404頁面:( – JamesG

+0

)如果這不起作用,那麼它看起來像它目前不可能與重寫。它會如果它是一個重定向。是否是一個選項? –

+0

我想沒有在地址欄中的URL更改,也沒有指定是否重定向類型,例如301等... – JamesG

-2
FireBase Allows for Static web hosting. It also has some Custom Behaviours 

https://firebase.google.com/docs/hosting/url-redirects-rewrites 

Redirects:: this is only for page forwarding 
Rewrites:: when you want to show the same content for multiple URLs [ it is there for URL reversing ]. 
It also provides control over the MIME types of the HTTP requests. 

現在,從上面的問題,我看到你正在嘗試從動態Web主機提供的頁面查詢DOM對象。

https://www.quora.com/How-are-dynamic-websites-hosted-1

+0

這個功能是可用的靜態網站,例如,下一個版本粉碎mag(https://next.smashingmagazine.com/)有這個選項。在靜態網站上也可以有動態內容。 – JamesG

+0

您提到的網站是靜態網站。我沒有在網站https://next.smashingmagazine.com/上找到任何類型爲「* .html?i =:item」的網址,因爲您在 –

+0

之上完成了請不要downvote有效答案if你不確定它@JamesG –