2017-06-18 58 views
2

我有一個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工作正常的直接調用,而斯利姆框架不再工作了。

有沒有想法?謝謝!

回答

0

我碰到了同樣的問題,我解決它通過讓所有我的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和所有生活在一個幸福的家庭同一屋檐下