【问题标题】:HTML5 Mode AngularJS ui.routerHTML5 模式 AngularJS ui.router
【发布时间】:2015-05-03 21:14:17
【问题描述】:

您好,我想使用 html5 模式。我的文件结构如下:

mypage.de/mysub

我只能在 mysub 中胡闹。

到目前为止,我添加到我的 index.html 中:

<base href="/mysub/">

并在 /mysub/ 中创建了一个新的(也是唯一的).htaccess

RewriteEngine on

# Don't rewrite files or directories

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]

如果我使用网址: mypage.de/mysub/#/site1 转化为mypage.de/mysub/site1 并加载

但如果我直接使用转换后的 url,例如:mypage.de/mysub/site1 我得到一个 404

服务器是 apache: 我查看了该教程: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

但我不确定服务器名称是什么,如果 /path/to/app 是

/

或

/mysub/

当我离开虚拟主机和目录标签中的部分时,它也会引发我已经内部服务器错误。

因为 .htaccess 在目录中。我试过差异。变化,但在这里没有任何效果,所以我只是使用了目录中的部分,如此处所述: AngularJS: can't get html5 mode urls with ui-route $state

【问题讨论】:

  • 它不是也切掉了整个#/sitex 部分吗?不会……像这样更好:正则表达式中的 mysub\/(#\/)?(.*)$

标签: angularjs html .htaccess angular-ui-router


【解决方案1】:

试试这个

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  RewriteBase /mysub/

  # Don't rewrite files or directories
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Rewrite everything else to index.html to allow html5 state links
  RewriteRule ^ index.html [L]
</IfModule>

【讨论】:

  • 不起作用它只显示404,所以我认为他不会重写。
  • 我在 test.php 中试过这个: 它返回 1: 所以它似乎被启用了
  • RewriteBase 是否相对于我的文档根目录?例如。 /srv/www/html/mysite.de/mysub/ 我需要 mysub 还是 /srv/www/html/mysite.de/mysub/
  • 他确实阅读了 .htaccess,因为在其中放入垃圾会导致内部服务器错误。
猜你喜欢
  • 2014-08-04
  • 2014-10-13
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
  • 2014-10-29
  • 1970-01-01
  • 2017-06-17
  • 2015-04-25
相关资源
最近更新 更多