【问题标题】:Angular 6 + Codeigniter same portAngular 6 + Codeigniter 相同的端口
【发布时间】:2019-03-12 09:29:15
【问题描述】:

我有一个 Angular 6 项目;在根目录的子目录中是带有 CodeIgniter (/api) 的服务器。

具有 404 的重定向配置到 web 的主页;我可以输入 api 的索引路径(/api/index.php),但任何深入 api 的路径都会将我重定向到网络的主页。

我想知道;如何告诉 Angular Routing 不要控制该路由 (/api) 或错误重定向的原因。

app.routes.ts

export const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', redirectTo: 'home',pathMatch: 'full'},
  { path: 'pages', redirectTo: 'pages', pathMatch: 'full' },
  { path: 'store', redirectTo: 'pagesstore', pathMatch: 'full' }, 
  { path: '**', redirectTo: 'home', pathMatch: 'full' },
];

.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Credentials true
</IfModule>

【问题讨论】:

    标签: angular codeigniter-3 .htaccess


    【解决方案1】:

    如果去掉通配符路由

    { path: '**', redirectTo: 'home', pathMatch: 'full' }
    

    您将能够访问 Codeigniter 视图。

    【讨论】:

    • 它可能会起作用,但问题是我会失去知道 404 被正确重定向的安全性。告诉路由某个路由无法控制它不是更好的方法吗?这可能吗?
    • 安全方面,Angular 不会对访问某些页面做任何事情,因为所有代码都存在于客户端上并且很容易被黑客入侵。您的后端必须保护数据安全......如果您想要一个 404 页面,我会使用 .htaccess 而不是您的情况下的通配符。
    • 不确定是否有办法告诉 Angular 在存在通配符时不要处理路由
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    相关资源
    最近更新 更多