【发布时间】:2025-11-23 00:00:02
【问题描述】:
我已经在我的 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>
【问题讨论】:
-
可能有助于显示网络服务器日志或您请求的逐字 URL。
-
请求 URL example.com/register 我收到此错误:在此服务器上找不到请求的 URL /register。
-
GET /register HTTP/1.1" 404 501 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0. 3396.99 Safari/537.36
标签: php angular apache .htaccess angular-routing