【问题标题】:.htaccess for angular html5 redirect not working用于角度 html5 重定向的 .htaccess 不起作用
【发布时间】:2015-04-28 10:30:24
【问题描述】:

我的.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]

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

【问题讨论】:

    标签: angularjs html apache .htaccess


    【解决方案1】:

    你有一个规则:

    RewriteRule ^.*$ - [NC,L]
    

    L flag 在您的 index.html 规则上方,所以我猜 index.html 规则甚至没有得到处理。更不用说,^.*$ 规则似乎不像no rewrite URL/URI specified 那样形成良好。相反,您似乎正在将所有请求重写为破折号 (-)。

    将文件更改为如下所示:

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

    【讨论】:

    • 谢谢 Alex,能否请您粘贴正确的 .htaccess 文件内容?
    • 尝试取消QSA 标志,并查看/etc/apache2 文件夹中的.conf 文件中是否有任何AllowOverride None 指令。
    • 我的 http.conf 文件中有这个标签: AllowOverride None Options None Order allow,deny Allow from all 仍然不工作...
    • 该指令是检查配置文件的好方法,因为它会导致 Apache 忽略您的 .htaccess 文件并使用配置文件中的重写规则。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2015-03-07
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多