通用的.htaccess的angularjs,随着HTML5的路由参数的工作原理 [英] Universal .htaccess for angularjs that works with HTML5 route parameters

查看:265
本文介绍了通用的.htaccess的angularjs,随着HTML5的路由参数的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是.htaccess文件我目前有:

Here is the .htaccess file I have currently:

    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]

它适用于网址是这样的:

It works for url's like this:

http://domain.com/view

http://domain.com/otherview

但是,如果我尝试做一个硬刷新的参数是这样的:

But if I try and do a hard refresh on parameters like this:

http://domain.com/view/3523

http://domain.com/view/1234/5322

如果我做硬刷新任何生成的参数的网页,它只是显示的index.html没有任何JavaScript加载,它打破了网页。

If I do a hard refresh on any parameter generated pages it just shows index.html without any Javascript loaded, which breaks the page.

参数的URL的工作,如果我浏览网页从应用程序内,否则他们不工作。

The parameter URL's work if I navigate to the page from within the app, otherwise they don't work.

我如何获取参数的URL的工作在AngularJS中的硬刷新。

How do I get parameter URL's to work on a hard refresh within AngularJS.

我也HTML5模式打开:

I also have HTML5 mode turned on:

$ locationProvider.html5Mode(真);

推荐答案

您可以使用下面的代替:

You can use the following instead:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [NC,L]

RewriteRule ^ index.html [NC,L]

这篇关于通用的.htaccess的angularjs,随着HTML5的路由参数的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆