2014-01-12 32 views
2

我部署了一個AngularJS應用程序,該應用程序使用lineman在heroku上使用lineman-angular模板構建。 Html5模式已啓用,我想修復頁面刷新時的「頁面未找到」問題。.htaccess on heroku for angularjs應用程序

在此之後answer我可以看到可以將規則添加到.htaccess文件中。

所以我創建了以下內容的文件:

<ifModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !index 
    RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png) 
    RewriteRule (.*) index.html [L] 
</ifModule> 

如果我把.htaccess文件在我的應用程序的根目錄,然後我的應用程序停止工作,我可以看到以下錯誤:

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request. 

我很困惑,我需要在heroku雪松應用程序上創建.htaccess文件。 任何人都可以幫助我嗎?

+0

你解決了嗎? – 2015-02-11 05:06:01

+0

我改用了Hashbang模式。 – Havrl

回答

0

過了一段時間,我決定重新考慮這個問題,例如,配置服務器端部署在啓用Html5模式的Heroku Angular.js應用程序上,這是使用Lineman.js構建的。

我檢查了heroku-buildpack-lineman,發現更新的信息,可能不需要定製生成包。 所以我也跟着他們的指示來配置官方Node.js的buildpack:

$ heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs 
$ heroku config:set NPM_CONFIG_PRODUCTION=false 

然後包括一個Procfile:

web: npm run production 

最後加入他們的生產腳本:

"scripts": {  
    "start": "lineman run",  
    "test": "lineman spec-ci",  
    "production": "lineman clean build && npm i [email protected] && node -e \"var e = require('express'), a = e(); a.use(e.static('dist/')); a.listen(process.env.PORT)\"" 
}, 

但我還使用捕獲所有路由中間件將快速重寫代碼包括到生產腳本中。

下面是修改後的生產腳本:

"production": "lineman clean build && npm i [email protected] && node -e \"var e = require('express'), a = e(); a.use(e.static('dist/')); a.use(function(req, res) { res.sendfile('dist/index.html'); }); a.listen(process.env.PORT)\"" 

現在部署在Heroku上的應用工程,我需要!

+0

我也面臨同樣的問題,你能提供關於如何解決這個問題的更多細節,我對這個解決方案有點迷惑。 –

+0

@MiladRk將上面的「腳本」片段插入到package.json中。然後,您的應用將使用配置爲處理路由重定向的節點快車運行(請參閱「生產」行)。 – Havrl

相關問題