首页 > 解决方案 > 将所有流量转发到一个子文件夹,将一个子文件夹转发到另一个子文件夹

问题描述

这是我服务器上文件夹逻辑的简化版本。

├── rest/
│   └── api/
│       ├── account
│       ├── posts
│       └── settings
├── src/
│   ├── index.html
|   ├── scripts.js
│   └── about/
|       └── index.html
└── public/
    ├── index.html
    ├── scripts.js
    └── about/
        └── index.html

服务器设置:Ubuntu 16.04 Apache 2

我想要实现的是:

这是我当前的.htaccess设置

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ /public/$1 [L,NC]

这适用于重定向//public/index.html但不适用于api.

标签: apache.htaccessmod-rewrite

解决方案


你不能这样做:

RewriteEngine On
RewriteBase /
RewriteRule ^(api/.*)$ /rest/$1 [L,NC]
RewriteRule ^(.*)$ /public/$1 [L,NC]

推荐阅读