This essentially is a repost of this question Since the question wasn't correctly answered.
这基本上是这个问题的重新发布,因为这个问题没有得到正确回答。
Using a basic set of self explainatory htaccess rewrites
使用一组基本的自解释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]
Consider the following links.
请考虑以下链接。
1. http://localhost/clouds
2. http://localhost/wind
3. http://localhost/city/Tokyo
Links 1 and 2 are working fine upon page refresh but link 3 is only accessible through page navigation (clicking the link). If I manually pase the third link in the browser I get to the Index page, unlike link 1 and 2.
链接1和2在页面刷新时工作正常,但链接3只能通过页面导航(单击链接)访问。如果我在浏览器中手动设置第三个链接,我会进入索引页面,这与链接1和2不同。
My route config:
我的路线配置:
theApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
"use strict";
console.log('Configuring');
$routeProvider.when('/clouds', {
templateUrl: 'Views/Cloud.html',
controller: 'cloudController'
}).when('/wind', {
templateUrl: 'Views/Wind.html',
controller: 'windController'
}).when('/city/:cityName', {
templateUrl: 'Views/City.html',
controller: 'cityController'
});
$locationProvider.html5Mode(true);
}]);
P.S. I did put . If i hadn't link 1 and 2 wouldn't be working.
附:我确实放了。如果我没有链接1和2将无法正常工作。
EDIT: My bad I did not add the anchor tags leading to these links.
编辑:我的坏我没有添加导致这些链接的锚标签。
<ul class="nav navbar-nav navbar-right">
<li><a href="#"> Home</a></li>
<li><a href="/clouds"> Cloud</a></li>
<li><a href="/wind"> Wind</a></li>
<li><a href="/city/Tokyo"> CHAT!!!</a></li>
</ul>
1 个解决方案
#1
1
You have to place the <base href="/" />
At the very top of the tag. It works, although I would like to know HOW AND WHY!!
您必须将
Credits: This * answer
致谢:这个*答案
#1
1
You have to place the <base href="/" />
At the very top of the tag. It works, although I would like to know HOW AND WHY!!
您必须将
Credits: This * answer
致谢:这个*答案