htaccess苗条和angular2

问题描述:

我有一个htaccess的问题,也许你可以帮助我。我的系统由一个angular2-app(单页面客户端应用程序,index.html)和一个slim-v3 php REST API(index.php)组成。 angular2-app访问REST API。如果可能的话,那么我想为angular2-app和Slim REST API使用相同的域。htaccess苗条和angular2

目前,htaccess的是这样的:

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

如果我通过的index.html启动angular2-app并去像如内容http://www.example.com/mycontent/id然后一切正常。 如果我直接调用URL http://www.example.com/mycontent/id,然后我从斯利姆(PHP)404

当我改变的htaccess到:

RewriteEngine On 
RewriteBase/
RewriteRule^index \ .html $ - [L] 
RewriteCond% {REQUEST_FILENAME}! -f 
RewriteCond% {REQUEST_FILENAME}! -d 
RewriteRule./Index.html [L] 

http://www.example.com/mycontent/id工作正常的直接调用,而斯利姆框架不再工作了。

有没有想法?谢谢!

我碰到了同样的问题,我解决它通过让所有我的API的生活中,并指着

/api/index.php 

然后我的.htaccess看起来是这样的:

RewriteEngine On 

# Handle API Requests 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} ^/api/ 
RewriteRule^/api/index.php [L] 


## pure angular routes 
RewriteBase/
RewriteRule ^index\.html$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.html [L] 

所以现在我的角应用程序是根,PHP API在/ API和所有生活在一个幸福的家庭同一屋檐下