我有一个网页,它的工作就好了。这个问题开始,当我需要刷新页面或尝试共享与他人的链接(甚至是在新标签中打开它)。
当我尝试这样做,该页面无法正常工作。它加载只页眉,页脚等,但不是在我的 NG-鉴于部分
,也没有CSS类,等等...
另外,我使用的是HTML5模式AngularJS本code:
$ locationProvider.html5Mode({
启用:真
});
我试图通过.htaccess重新加载页面,它的工作,但只适用于第一个链接。例如 site.com/News
加载好了,但如果我尝试刷新/股的页面 site.com/News/4
(都到一个单独的新闻页面),那么它将无法工作了。
这是在使用了$ C $词我的.htaccess
文件
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)/index.html
< / IfModule>
解决方案
试试这个:
RewriteEngine叙述上
的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -d
重写规则^ - [L]
重写规则^ /index.html
I have a webpage and it's working just fine. The problem starts when i need to refresh the page or try to share a link with someone (or even open it in a new tab).
When i try to do it, the page doesn't work. It loads only the header, footer, etc. But not the part inside my ng-view
and also no css class, etc...
Also, I'm using html5 mode in AngularJS with this code:
$locationProvider.html5Mode({
enabled:true
});
I tried to use a .htaccess to reload the page and it's working, but only for the first link. For example site.com/News
is loading ok, but if I try to refresh/share the page site.com/News/4
(which goes to an individual news page) then it won't work anymore.
This is the code i used in my .htaccess
file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html
</IfModule>
解决方案
Try this:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html