Angular html5Mode重定向到文档根目录

时间:2015-03-25 15:08:54

标签: angularjs angularjs-routing

我已使用html5Mode从我的Angular应用程序中删除了#标记。但它重定向到文档根目录。

即我的申请网址为http://example.com/webapp/#/home

使用html5mode时,新网址看起来像http://example.com/home而不是http://example.com/webapp/home

注意:这里我的角度应用程序文件位于http://example.com/内的webapp文件夹中。

我还尝试在http://example.com/webapp/中创建.htaccess文件。

我的.htaccess文件包含

RewriteEngine   On
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     . /index.html [L]

如何访问我的主页http://example.com/webapp/home

由于

2 个答案:

答案 0 :(得分:0)

试试这个htaccess conf(把它放在根目录中):

RewriteEngine On  
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  # If the requested resource doesn't exist, use index.html
  RewriteRule ^ /webapp/index.html

Source

答案 1 :(得分:0)

我可以通过提供类似

的html来解决这个问题
<html>
  <head>
    <base href="/webapp/index.html" />
    .....
相关问题