Apache 将所有流量转发到子文件夹,并将一个子文件夹转发到其他子文件夹
这是我服务器上文件夹逻辑的简化版本Apache 将所有流量转发到子文件夹,并将一个子文件夹转发到其他子文件夹,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,这是我服务器上文件夹逻辑的简化版本 ├── rest/ │ └── api/ │ ├── account │ ├── posts │ └── settings ├── src/ │ ├── index.html | ├── scripts.js │ └── about/ | └── index.html └── public/ ├── index.html ├── scripts.js └── about/
├── rest/
│ └── api/
│ ├── account
│ ├── posts
│ └── settings
├── src/
│ ├── index.html
| ├── scripts.js
│ └── about/
| └── index.html
└── public/
├── index.html
├── scripts.js
└── about/
└── index.html
服务器设置:
Ubuntu 16.04
阿帕奇2
我试图实现的是:
- 访问
将显示/
/public/index.html
- 访问
将显示/about
/public/about/index.html
- 访问
将显示/api/account
/rest/api/account
.htaccess
设置
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ /public/$1 [L,NC]
这对于将/
重定向到/public/index.html
非常有效,但对于api
则不行。您不能:
RewriteEngine On
RewriteBase /
RewriteRule ^(api/.*)$ /rest/$1 [L,NC]
RewriteRule ^(.*)$ /public/$1 [L,NC]
你不能:
RewriteEngine On
RewriteBase /
RewriteRule ^(api/.*)$ /rest/$1 [L,NC]
RewriteRule ^(.*)$ /public/$1 [L,NC]
/about
到/src/about/index.html
?@vivek_23不,到/public/about/index.html
-我的错误,它在结构概述中丢失,现在更新。ok,您当前的规则是否没有给您太多重定向问题?@vivek_23我认为不应该-我认为重写是内部的,因此客户端不应该提出请求again@arco444即使URL保持不变,Apache也会执行内部重定向。在此过程中,它在浏览器中显示了一个服务器错误,并且由于日志中可能存在配置错误,请求超出了10次内部重定向的限制。/about
到/src/about/index.html
?@vivek_23 nope,到/public/about/index.html
-我的错误,它在结构概述中丢失了,现在更新。好的,你当前的规则没有给你太多的重定向问题吗?@vivek_23我认为不应该-我认为重写是内部的,所以客户端不应该提出请求again@arco444即使URL保持不变,Apache也会执行内部重定向。在此过程中,它显示浏览器中出现服务器错误,并且由于日志中可能存在配置错误,请求超出了10次内部重定向的限制。令人惊讶的是,这正是我上周一直在寻找的!有谁能推荐一个好的重写教程吗?太棒了,这正是我上周一直在寻找的!有人能推荐一个好的重写教程吗?