htaccess苗条和angular2 [英] htaccess slim and angular2

查看:78
本文介绍了htaccess苗条和angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在htaccess上遇到问题,也许您可​​以帮助我。我的系统由angular2-app(单页客户端应用程序,index.html)和slim-v3 php REST API(index.php)组成。 angular2-app访问REST API。如果可能的话,我想对angular2-app和苗条的REST API使用相同的域。

I have problems with a htaccess, maybe you can help me. My system consists of an angular2-app (single page client side app, index.html) and a slim-v3 php REST API (index.php). The angular2-app accesses the REST API. If possible, then I would like to use the same domain for the angular2-app and the slim REST API.

目前,htaccess如下所示:

At the moment, the htaccess looks like this:

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]

如果我启动angular2-app通过index.html转到内容,例如 http://www.example.com/mycontent/id ,然后一切正常。
如果直接调用URL http://www.example.com/mycontent/id ,那么我从Slim(PHP)获得404

If i start the angular2-app via index.html and go to content like e.g. http://www.example.com/mycontent/id then everything works fine. If I call the URL http://www.example.com/mycontent/id directly, then I get a 404 from Slim (PHP)

当我将htaccess更改为:

When i change the htaccess to:

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 正常工作,但是Slim-Framework不再工作。

the direct call of http://www.example.com/mycontent/id works correctly, but the Slim-Framework does not work anymore.

有人有想法吗?谢谢!

推荐答案

我遇到了同样的问题,我将所有api都放在里面并指向了

I came across the same issue, i solved it by having all my api's living in and pointing to

/api/index.php

然后我的.htaccess如下:

Then my .htaccess looks like this:

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]

现在,我的Angular应用程序位于/ api的php API的根目录下所有人都和一个幸福的家庭生活在同一屋檐下

So now my Angular app is at root, php API in /api and all live under the same roof as one happy family

这篇关于htaccess苗条和angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆