.htaccess for angular HTML5 重定向不起作用



我的.htaccess文件:

RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) /index.html [NC,L]

放置在根目录内(与索引.html一起)。但是,当我进行刷新时,出现错误:The requested URL <url> was not found on this server 。同一 URL 正在应用链接中工作。我的.htaccess文件有问题吗?

您有一条规则:

RewriteRule ^.*$ - [NC,L]

L标志位于index.html规则上方,所以我猜index.html规则甚至没有得到处理。更不用说,^.*$规则似乎格式不佳,因为没有指定重写 URL/URI。相反,您似乎正在将所有请求重写为破折号 ( - )。

将文件更改为如下所示:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* /index.html [QSA,NC,L]

最新更新