我的web项目的目录结构如下所示:
webroot/
├── web/
│ ├── backend/
│ │ ├── endpoint/
│ │ │ └── endpoint.php
│ │ └── ...
│ └── frontend/
│ ├── app/
│ │ └── ...
│ ├── assets/
│ │ └── ...
│ ├── index.html
│ └── app.js
└── .htaccess如您所见,我的前端(AngularJS)驻留在/web/frontend中。为了能够使用更简单的规范网址访问应用程序,我创建了以下.htaccess文件,该文件基本上将www.example.com/映射到www.example.com/web/frontend/
RewriteEngine On
RewriteBase /
# 1: css/js/img files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/(.*)$ web/frontend/assets/$1 [QSA,L]
# 2: AngularJS app/files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app/(.*)$ public/frontend/app/$1 [QSA,L]
# 3: Backend/API -- this rule seems to be ignored
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^endpoint/(.*)$ web/backend/endpoint/$1 [QSA,L]
# 4: redirect to canonical URL
RewriteCond %{THE_REQUEST} public/frontend/
RewriteRule ^web/frontend/(.*) http://<host>/$1 [R=301,L]
# 5: everything else to be routed by AngularJS
RewriteCond %{REQUEST_URI} !web/frontend/
RewriteRule ^(.*)$ /web/frontend/#/$1 [L]这对于前端部分工作得很好,这意味着应用程序-包括所有资产-由浏览器正确加载。
我正在努力解决的问题基本上就是后端访问。根据我的理解,我应该能够通过/endpoint/endpoint.php?foo=bar检索/web/backend/endpoint/endpoint.php?foo=bar,因为规则#3告诉Apache这样做。
相反,每次我访问/endpoint/endpoint.php?foo=bar时,服务器都会返回前端的index.html (这意味着执行规则#5 )。
我遗漏了什么?
发布于 2017-03-12 10:27:03
此规则中存在一些语法错误,请检查。如果您对此进行了注释,则重定向到终结点的操作将按预期进行。
# 5: everything else to be routed by AngularJS
RewriteCond %{REQUEST_URI} !web/frontend/
RewriteRule ^(.*)$ /web/frontend/#/$1 [L]所以你需要用正确的语法来修正规则#5,否则你的php文件将不会被映射,并且由于.htaccess文件中的错误,它将不允许执行php文件。
https://stackoverflow.com/questions/42738698
复制相似问题