配置htaccess以使用Angular和PHP路由

配置htaccess以使用Angular和PHP路由,php,angular,.htaccess,mod-rewrite,Php,Angular,.htaccess,Mod Rewrite,我试图使用Angular 4和PHP路由,但我无法配置它以同时使用这两种路由。我可以和其中一个一起工作,但不是两个都能 这是我的文件夹结构: root │ index.html │ vendor.bundle.js | [..other angular files..] │ └─api │ │ index.php │ │ init.php │ │ │ └─vendor └─assets └─[..other project files..] 在文件api/index.php

我试图使用Angular 4和PHP路由,但我无法配置它以同时使用这两种路由。我可以和其中一个一起工作,但不是两个都能

这是我的文件夹结构:

root
│ index.html
│ vendor.bundle.js    
| [..other angular files..]  
│
└─api
│  │ index.php
│  │ init.php
│  │
│  └─vendor
└─assets
└─[..other project files..]
在文件
api/index.php
中,我正在设置php路由

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . api/index.php [L]

    RewriteBase /
    RewriteRule ^index.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</IfModule>

因此,当我使用这个
.htaccess
时,PHP路由按预期工作,但当我刷新页面时,角度路由不工作,因为它被视为PHP路由

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . api/index.php [L]

    RewriteBase /
    RewriteRule ^index.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</IfModule>
在这段代码中,角度路由可以工作,即使在我刷新页面时也是如此,但是PHP路由从不重定向到index.PHP文件,因此它总是返回null


我需要做什么来解决这个问题?

因为我对htaccess了解不多,我不知道这个答案是否100%正确,但我成功地使它工作了

我所做的是将行
RewriteBase/
移到顶部,并删除
RewriteRule^index.html..
,最后的
.htaccess
如下所示:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} api
RewriteRule . api/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

重新启动发动机
重写基/
重写cond%{REQUEST_URI}api
重写规则。api/index.php[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.html[L]
现在,这是预期的工作。如果有人有更好的答案,我就把这个问题留待讨论