如何重定向Ionic /网站中的子文件夹

问题描述 投票:0回答:1

我目前有一个以x url托管的离子Web应用程序(例如www.myApp.com)。我的应用包含子文件夹,例如myApp.com/home或myApp.com/details。不幸的是,每当刷新这些子文件夹中的任何一个时,都会出现类似“ Cannot GET / home”的错误(仅基本URL /域有效)。

[如果可能的话,有没有办法在Google Domains上托管这些子文件夹(因此GD会在刷新后将这些链接自动重定向回baes myApp.com链接),或者我是否需要在代码本身来完成此任务?

angular ionic-framework browser web-development-server
1个回答
0
投票

如果我理解正确,您需要告诉您的服务器它应该将请求重定向到您的index.html,以便Ionic可以处理路由。

在Apache上,您可以在根文件夹中添加具有以下内容的.htaccess文件:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

来源:https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

© www.soinside.com 2019 - 2024. All rights reserved.