一个网站的不同部分/路线是否可能具有多个Slim应用程序对象。
例如:
我已经尝试使用以下命令修改Apache的.htaccess:
RewriteRule ^api front_controller_api.inc.php [QSA,L]
RewriteRule ^admin-panel front_controller_admin.inc.php [QSA,L]
...但是这似乎违反了Slim的路由原则,因为Slim认为/ api和/ admin-panel是请求URI的一部分。对于页面的每个部分,使用具有不同配置,中间件等的不同应用程序对象会容易得多。
任何的想法?
我不知道这是否是正确的方法,但是您尝试这样的文件夹结构:
public/
|-> api/
|-> index.php
|-> .htaccess
|-> admin-panel/
|-> index.php
|-> .htaccess
更新:
我“调查”了更多,并提出了另一种解决方案:
public/
|-> .htaccess
|-> admin-panel.php
|-> api.php
.htaccess
:
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin-panel/ admin-panel.php [QSA,L]
RewriteRule ^api/ api.php [QSA,L]
更新2:
使用此解决方案,您必须将所有分组'/admin-panel'
或分组到'/api'
路由定义中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句