gpt4 book ai didi

php - 子页面上的 Angular 2 apache .htaccess 文件 404

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:06 24 4
gpt4 key购买 nike

我已经在我的 apache 服务器上成功安装并运行了 Angular 2 应用程序,我可以通过 [routerLink]="['/register']" 浏览页面

但是,当我刷新页面时,我在注册页面上收到 404 错误。我的重写规则有问题吗:

Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>

这也是我的 apache VirtualHost

<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/front/dist/browser
<Directory /var/www/html/front>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

最佳答案

您可以通过将 404 错误重定向到您的 index.html 来解决它

– 在 Apache 服务器托管中,编辑 Apache 配置:

sudo nano/etc/apache2/sites-enabled/000-default.conf

– 像这样添加 ErrorDocument 404:我的 index.html 位于/var/www/html/vas/index.html

– 完整文件:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# redirect 404 to index page
ErrorDocument 404 /vas/index.html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

– 通过命令 sudo service apache2 restart 重启 Apache 服务器

关于php - 子页面上的 Angular 2 apache .htaccess 文件 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51714422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com