我知道这个问题在堆栈溢出中被问了很多次,但我无法得到正确的结果。
我试过这个链接:角度路由的htaccess重定向
https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode
所以基本上,我在我的应用程序中使用 https://github.com/angular-ui/ui-router 进行导航,
我们有这样的网址:
-
www.xyz.com/products <=此URL工作正常,(硬刷新时工作正常)
-
www.xyz.com/displayOrders/12 <= 当我们这样做时,此 URL 不起作用 从浏览器硬刷新。为什么?
我的嵌套视图也不起作用:
- www.xyz.com/message/notfication/12
我在.htaccess文件中写的是:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule (.*) index.html [L]
</IfModule>
我的基本标签是这样的:
<base href="/"> and i also made html5mode as true in app.js
你应该这样写.htaccess
。<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule (.*) /index.html [L]
</IfModule>
如果你的项目在子目录示例:www.xyz.com/shop/
你应该像这样写最后重写规则
RewriteRule (.*) /shop/index.html [L]
和像这样的基本标签
<base href="/shop/">