刷新角度路线时的404

时间:2017-03-06 00:15:58

标签: angularjs apache .htaccess mod-rewrite

我已经尝试过了

<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.任何想法?

聚苯乙烯。我正在使用ui-route $locationProvider.html5Mode(true);所以路由没有#,路由IS /登录,这在所有场景中都有效....除了刷新一个

1 个答案:

答案 0 :(得分:0)

主要问题在于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]
相关问题