Apache 2.4-透明地重定向到子文件夹 [英] Apache 2.4 - transparently redirect to subfolder

查看:83
本文介绍了Apache 2.4-透明地重定向到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我透明地将每个请求(html,css,js等)重定向到子文件夹_site(其中,我的静态 Jekyll 网站位于...)

I am transparently redirecting every request(html, css, js,...) to a subfolder _site (where my static Jekyll site sits...)

RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$  _site/$1 [L]

基本上可以.尽管我觉得很奇怪,但是我必须使用Rewrite条件来阻止迭代:

That basically works. Although I find it rather strange, that I have to use the Rewrite condition, to block iterations:

AH00124:由于可能的配置错误,请求超出了10个内部重定向的限制.如果...,请使用'LimitInternalRecursion'增加限制.

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if ...

毕竟,我最后一次使用 [L]作为最后一个,那么为什么我会递归?!?

如果我尝试阻止直接访问站点文件夹(例如example.com/_site/favicon.ico),请在第一行之前加上

After all, I am using [L] for last, so how come, I end up in recursions?!?

If I try to prevent direct access to the site-folder (like example.com/_site/favicon.ico), be prepending this first line:

RewriteRule ^_site.* - [R=403,NC,L]
RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$  _site/$1 [L]

然后,同样在合法访问权限(example.com/favicon.ico)上,我得到403!

Then, also on legitimate access (example.com/favicon.ico) I get a 403!

显然,每个请求都要经过另一轮.合法的,然后在第二回合"中与禁止的规则相匹配.那么,这是怎么了?

Apparently, every request takes another round. The legitimate ones, then in "round 2" match the forbidden rule. So, what's wrong here?

为什么"last"不是"last"?(发生了什么变化,例如,在Apache 2.2和2.4之间?因为.htaccess上的很多东西都发生了变化...)

Why doesn't „last" mean „last"? (did something change, i.e. between Apache 2.2 and 2.4? as quite a few thing changed on .htaccess there...)

推荐答案

咳嗽,持续"并不完全意味着持续".它仅表示

Cough, „Last" doesn't quite mean „last". It only means

立即退出此文件中的重写,忽略其余各行".

„quit rewriting within this file now, ignore the rest of the lines".

但这也意味着

„使用新的(重写的)URL重新运行整个htaccess内容.

„re-run the whole htaccess-thing with that new (rewritten) url.

(如果您的重写规则过于具体而无法触发递归,那么您可能不会对YEARS有所注意...即使说实话,

(Something you might not notice for YEARS, if your rewrite rules are too specific to trigger recursions... even, if in all honesty, its in the docs)

所有人,祝您递归愉快.要真正结束一切,请猜测什么:

So, happy recursion, everyone. To truly put an end to things, guess what:

RewriteRule ^(.*)$  _site/$1 [END]

...分别在我的扩展版本中:

... respectively in my extended version:

RewriteRule ^_site.* - [R=403,NC,END]

RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$  _site/$1 [END]

(.. ,L,END没什么问题,但是END暗示L)

( .. ,L,END doesn't hurt, but END implies L)

这篇关于Apache 2.4-透明地重定向到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆