且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular和PHP .htaccess文件重定向问题

更新时间:2023-09-12 11:00:22

我使用完全相同的堆栈来编写应用程序(Angular Front End/Slim API).我的第一个应用程序遇到了与您完全相同的问题,因为这两个框架都需要.htaccess重定向并且正在争夺控制权.

I use the exact same stack for writing applications ( Angular Front End / Slim API ). My first application ran into the same exact issue you were having, that being that both frameworks needed the .htaccess redirect and were fighting for control.

我的解决方案很简单.Angular是我直接放置在面向公众的文件夹中的前端控制器(在我的情况下为/public_html ).Slim被放置在名为/api 的公共文件夹内的文件夹中.

My solution was rather simple. Angular being the front end controller i placed directly in my public facing folder ( in my case /public_html ). Slim was placed in a folder inside my public folder named /api.

通过这种方式,Angular在公用文件夹中拥有自己的.htaccess文件,并且可以通过/public_html/api 路径访问我的API,并且能够拥有自己的.htaccess文件.

This way Angular has it's own .htaccess file in the public folder, and my API was accessible via the /public_html/api path and was able to have it's own .htaccess file.

我的文件结构:

/public_html
   .htaccess ( ANGULAR )
   { Angular Files }
   /api
     .htaccess
     { Slim Files ( index.php ) }

应用程序网址: https://myapplication.com API URL: https://myapplication.com/api

App URL: https://myapplication.com API URL: https://myapplication.com/api

您的Angular .htaccess文件应包含重定向:

Your Angular .htaccess should contain the redirect:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://yourapp.com/index.html [QSA,L]

您的Slim .htaccess文件应包含以下内容:

Your Slim .htaccess should contain something like:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]