404刷新时角路线
问题描述:
我已经试图把404刷新时角路线
<base href="/index.html"> and/or <base href="/">
我已经配置我.htacess这样的:
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index1.html [L]
</ifModule>
这:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# If the requested pattern is file and file doesn't exist, send 404
RewriteCond %{REQUEST_URI} ^(\/[a-z_\-\s0-9\.]+)+\.[a-zA-Z]{2,4}$
RewriteRule^- [L,R=404]
RewriteRule ^(.*) index.html [NC,L]
而且我也知道我的mod_rewrite已启用:
apache2ctl -M^C
> rewrite_module (shared)
这适用于加载家庭,并点击所有链接...但是,如果我打开/通过点击登录,它会正常打开。但是如果我只是重新加载它,或者输入相同地址的url地址,它将不起作用,它会给我404。任何想法?
Ps。我正在使用ui-route $locationProvider.html5Mode(true);
所以路由没有#,路由IS /登录,并且这可以工作....除了刷新之外的所有场景
答
主要问题是在apache2.conf ,我不知道我必须allowRewrite: All
不仅在sites-available/default
,而且在apache2.conf
。 所以,这个工作对我来说:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api
# otherwise forward it to index.html
RewriteRule ^.*$ - [NC,L]
RewriteRule ^. index.html [NC,L]
没有一个重写规则的主人,但你有你需要添加一个规则的问题将接受'/ login'和重定向/重写'/index.html#登录“或类似的根据你的'角路由器'设置..当你执行页面刷新请求命中服务器,返回404登录'不存在作为服务器资源..这只是一个路线在你的角度的应用程序 – Searching
但我不能为每条路线做这些......这就是为什么我使用这个:'RewriteRule ^(。*)index.html [NC,L]'一切(例如登录)应重定向到索引....我使用ui-route htmlMode true,所以没有“#”的url – Gabrielle
你有没有试过ui-serf –