Mus*_*niz 3 routes refresh http-status-code-404 flutter
在主要方法中,我使用了 UrlStrategy 包,如下所示,因为我不想在我的网址中包含 #:
void main() {
setPathUrlStrategy();
runApp(const MyApp());
}
Run Code Online (Sandbox Code Playgroud)
我在调试模式下测试网站时,没有问题。然后我发布了我的网站。主页就像www.example.com,当我尝试用F5刷新页面时,没有问题。然后我导航到另一个页面,例如www.example.com/about-us并尝试再次使用 F5 刷新页面,但出现“404 not found”错误。
为了解决这个问题,我在 htdocs 中创建了 .htaccess 文件并在该文件中写入:
RewriteEngine on
RewritwCond %{REQUEST_FILENAME} !-d
RewritwCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.html [L]
Run Code Online (Sandbox Code Playgroud)
但我开始收到 500 内部服务器错误。
htdocs 之外存在一个现有的 .htaccess 文件。我复制了上面的代码并将其粘贴到现有的 .htaccess 中。但又出现同样的问题。现有.htaccess文件中的代码如下:
##################################################
#
# DO NOT EDIT THIS FILE
#
# Create a new .htaccess file in your htdocs
# directory (or example.com/htdocs/ directory)
# to add your own rules or override these rules.
#
##################################################
DirectoryIndex index.php index.html index.htm index2.html
ErrorDocument 403 https://infinityfree.net/errors/403/
ErrorDocument 404 https://infinityfree.net/errors/404/
ErrorDocument 500 https://infinityfree.net/errors/500/
Run Code Online (Sandbox Code Playgroud)
我必须做什么?
我在 htdocs 中创建了一个名为 .htaccess 的文件。我粘贴了下面给出的代码:
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.html|assets|robots\.txt|favicon\.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.html [L]
Run Code Online (Sandbox Code Playgroud)
问题已经解决了。
| 归档时间: |
|
| 查看次数: |
4697 次 |
| 最近记录: |