htaccess 搭配 angular 10 放在二级目录

Fork Me On Github

angular 项目打包放在二级目录

例如:

把一个项目放在 backend 文件夹下

那么 需要设置

index.html

html
 
 <base href="/backend/">
1

最好把所有页面放在一个 backend 的路由下

ts
    
{
    path: 'backend',
    loadChildren: () => import('./backend/backend.module').then(m => m.BackendModule)
}
1234

这样在本地使用时生成的网址时

 
http://localhost:4200/backend/home
1

打包生成的网址也会是

 
http://zodream.cn/backend/home
1

但是这是刷新页面的话并不能指向 angular 程序

需要在网站根目录加上一个 .htaccess 的文件(PS:我用的时apache)

          
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    RewriteRule ^backend/[^\.]+$ backend/index.html
</IfModule>
12345678910

加上一句 RewriteRule ^backend/[^\.]+$ backend/index.html 就把路径指向 angular 程序了。

再次刷新网址 http://zodream.cn/backend/home 就能争取打开了

点击查看全文
标签: angular
0 409 0
在 angular 项目中实现对页面的访问控制
按下回车键,焦点移动到下一个表单或提交表单
使用ng-template 显示tree结构数据
使用 ViewContainerRef.createComponent 替代 ComponentFactoryResolver
angular 12使用 KaTex 显示 AsciiMath 格式的公式