php - 公共文件夹 .htaccess 中的 Slim 框架 index.php
问题描述
我正在使用 Slim Framework v3,特别是我正在使用这个项目:https ://github.com/slimphp/Slim-Skeleton
我的问题是在 apache 服务器上运行我的项目,如果我尝试使用此 url http://localhost/slim-app/some_route 访问我会收到此错误:
但是,如果我尝试导航到http://localhost/slim-app/public/some_route它可以工作。
我的文件夹结构如下所示:
/slim-app
.htaccess
/logs
/public
/css
/js
index.php
.htaccess
/src
/helpers
routes.php
settings.php
/templates
file.twig
/vendor
这是根项目文件夹“slim-app”中的 .htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /slim-app/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
这是公共目录中的 .htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the above doesn't work you might need to set the `RewriteBase` directive manually, 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 ^ index.php [QSA,L]
</IfModule>
解决方案
推荐阅读
- vue.js - 在内部存储中显示视频 (Vue)
- php - 忽略对 is_countable 的检查的 sizeof 的替代方案
- nlp - 对于服务机器人,我应该使用 ChatScript 还是 Rasa?
- ios - 停止更新地图查看位置
- amazon-web-services - CloudFormation 堆栈与导出的值和 Taskcat
- azure-storage - 从 SAS url 尝试 Azcopy 给出错误
- c# - COM 参考“XyzLib”是 ActiveX 控件“AxXyzLib”的互操作程序集,但被编译器标记为使用 /link 标志链接
- python - Python AttributeError: __enter__ 来自导入库中的 self.request
- apache - 使用ab进行性能测试时,发现负载均衡后性能有所下降?
- video - Pytorch Tensorboard SummaryWriter.add_video() 产生不良视频