2016-08-18 143 views
1

概述的「替換」:類型錯誤:無法讀取屬性未定義

我想訪問者重定向默認頁面(的index.html)的目錄結構中,以顯示在目錄使用.htaccess訪問文件(截至目前當前目錄index.html正在加載)。

但是,當我打開$locationProvider.html5Mode(true)在我的角度應用程序獲取低於錯誤。

控制檯錯誤:應用程序的

enter image description here

目錄結構:

public_html 
    --prod 
    --public 
     --app 
     --controllers 
     --directives 
     --services 
     --app.config.js 
    --index.html 
    --.htaccess 
.htaccess 

的public_html=>的.htaccess:

DirectoryIndex prod/public/index.html 

.htaccess直接用於使用域名的應用程序頁面(prod/public/index.html)的訪問者重定向,截至目前,當用戶訪問該域名(public_html)的index.html加載當前目錄。

的public_html=>督促=>的.htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /prod/public/ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*) /prod/public/#/$1 
    RewriteCond %{HTTP_HOST} ^example.com [NC] 
    RewriteRule ^(.*)$ http://www.example.com/prod/$1 [L,R=301] 
</IfModule> 

督促=>公共=>的index.html:

<base href="/prod/public/"> 

一切工作正常如果我從我的app.config.js文件中刪除$locationProvider.html5Mode(true).So,當我註釋掉$locationProvider代碼時,在#模式下一切正常工作。我可以到/#/abc等沒有問題。只要我把$locationProvider零件放回去,什麼都不會發生。

堆棧溢出相關的問題,但沒有成功:

$locationProvider.html5Mode(true) issues

Angular html5 mode not working in apache

回答

1

裏面public_html => .htaccess有這樣的規則,而不是:

DirectoryIndex index.html 
RewriteEngine On 

RewriteRule ^/?$ prod/public/index.html [L] 

然後public_html => prod => .htaccess應該有這樣的:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^public/index.html [L] 
+0

請問你能解釋一下這些行嗎?我想''urls'沒有'#'。 –

+0

我沒有試圖改變你的顯示規則。我發現的主要問題是「DirectoryIndex prod/public/index.html」不正確,不會將域請求重寫爲「/ prod/public/index.html」,因爲「DirectoryIndex」只設置默認處理程序文件。不幸的是,我對angularjs知之甚少,所以我只能在Apache方面提供幫助。測試我的更新規則,看看是否能解決您的問題。 – anubhava

+1

其按預期工作。謝謝 –

相關問題