Angular 部署了 2 个应用程序,当我转到 mydomain 时抛出 404。com/search
Angular 2 app deployed and throws a 404 when I go to mydomain.com/search
我定义了一些路线。这是一个片段:
const appRoutes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'search',
component: SearchComponent
}
]
我的应用程序现在已经部署,但我无法转到 mydomain.com/search
等直接路由,因为我收到了 404。但是,我可以转到 mydomain.com/
和从主页点击 link 到 /search
。效果很好。
我正在使用 Apache。我怎样才能解决这个 404 问题,以便我可以转到 mydomain.com/search
并通过显示搜索页面让它正常工作?
我知道有一种方法可以使用散列定位策略来执行此操作,但我很想知道在 apache 服务器上执行此操作的方法。
谢谢!
添加到 .htaccess 文件或 httpd.conf
<IfModule mod_rewrite.c>
RewriteEngine On RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
需要将 AllowOverride 选项添加到 httpd.conf
中的目录
这里/var/www/html是我项目的根目录
将 .htaccess 文件添加到您的项目
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
我定义了一些路线。这是一个片段:
const appRoutes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'search',
component: SearchComponent
}
]
我的应用程序现在已经部署,但我无法转到 mydomain.com/search
等直接路由,因为我收到了 404。但是,我可以转到 mydomain.com/
和从主页点击 link 到 /search
。效果很好。
我正在使用 Apache。我怎样才能解决这个 404 问题,以便我可以转到 mydomain.com/search
并通过显示搜索页面让它正常工作?
我知道有一种方法可以使用散列定位策略来执行此操作,但我很想知道在 apache 服务器上执行此操作的方法。
谢谢!
添加到 .htaccess 文件或 httpd.conf
<IfModule mod_rewrite.c>
RewriteEngine On RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
需要将 AllowOverride 选项添加到 httpd.conf
中的目录这里/var/www/html是我项目的根目录
将 .htaccess 文件添加到您的项目
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>