GoDaddy上路由链接角度为4的错误

时间:2017-12-18 04:00:52

标签: angular routing

我的网站出现问题。它是用Angular 4编写的。

问题在于:我只能使用以下链接:www.mywebsite.com 如果我使用例如:www.mywebsite.com/page,www.mywebsite.com / page1 它会给我一个错误。这意味着,如果我首先访问mywebsite.com然后点击链接,那么它会显示正确的页面。但是,如果我将浏览器mywebsite.com/page放入,那么它会给我错误页面。

我正在使用标准角度路由器并将其托管在GoDaddy上。知道为什么会这样吗?

1 个答案:

答案 0 :(得分:4)

好的,我找到了解决方案 - 这里: https://www.godaddy.com/community/VPS-Dedicated-Servers/Using-Angular-2-routing-on-Linux-Hosting-with-cPanel/m-p/33959#M1119

简而言之,您需要在.htaccess文件中添加以下代码:

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

如果myapp目录是主机服务上的应用程序所在的主目录