Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 将所有流量转发到子文件夹,并将一个子文件夹转发到其他子文件夹_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

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次内部重定向的限制。令人惊讶的是,这正是我上周一直在寻找的!有谁能推荐一个好的重写教程吗?太棒了,这正是我上周一直在寻找的!有人能推荐一个好的重写教程吗?