1

概述 :

我想将访问者重定向到目录结构内的默认页面(index.html)上,以便在使用.htaccess文件访问目录时显示(目前正在加载当前目录 index.html)。

但是当我$locationProvider.html5Mode(true)在我的角度应用程序中打开时,会出现以下错误。

控制台错误:

在此处输入图像描述

应用程序的目录结构:

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

public_html => .htaccess :

DirectoryIndex prod/public/index.html

这用于通过使用域名直接.htaccess重定向应用程序页面 () 上的访问者,截至目前,当用户访问当前目录 ( ) index.html 正在加载的域时。prod/public/index.htmlpublic_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/">

一切正常如果我$locationProvider.html5Mode(true)从文件中删除。app.config.js所以,当我注释掉$locationProvider代码时,一切正常#/#/abc我可以毫无问题地到达等。一旦我把$locationProvider零件放回去,什么都没有发生。

Stack Overflow 上的相关问题没有成功:

$locationProvider.html5Mode(true) 问题

Angular html5 模式在 apache 中不起作用

4

1 回答 1

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]
于 2016-08-22T07:16:05.287 回答