htaccess 从重写规则中排除 1 个文件夹

发布于 2025-01-05 15:23:42 字数 1142 浏览 0 评论 0原文

根据我的值 IS_HTTP,我在下面的代码之后决定 URL 应该是 https 还是 http。

我希望 http://mydomain.com 始终使用 http(从 https 重定向)(有一个空的 QUERY_STRING),http://mydomain.com/?q=homehttp://mydomain.com/?qq=home。 下面的代码适用于此类 URL,它将 IS_HTTP 设置为 1。一切都很完美。但我还希望管理文件夹的 URL 始终为 httpS,因此我想从该块中排除此类 URL。

这就是为什么我将第二个字符串添加到下面的代码中,但这并不能阻止此类 URL 应用 RewriteRule ^ - [E=IS_HTTP:1]。为什么?

#determine if page is supposed to be http
RewriteCond %{REQUEST_URI} !^administration [NC]
#if it has q=home or qq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(q=home|qq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]

再次,我希望在 RewriteRule ^ - [E=IS_HTTP:1] 之前停止 https://mydomain.com/administration/index.php 以及文件夹 /administration 中的所有其他文件 为什么上面的代码不能阻止他们?

我尝试过的第二个字符串是:

RewriteCond %{REQUEST_URI} !^administration [NC]
RewriteCond %{REQUEST_URI} !^/administration [NC]

但它们都不起作用。 (我相信这里不需要 /,因为 REQUEST_URI 不是从 / 开始,但我可能是错的)。

谢谢。

Depending on my value IS_HTTP, I decide after the code below, whether URL should be https or http.

I want always http (redirected from https) for http://mydomain.com (has an empty QUERY_STRING), http://mydomain.com/?q=home, http://mydomain.com/?qq=home.
And the code below works fine for such URLs, it sets up IS_HTTP to 1. Everything is perfect. But I want also URLs to administration folder always to be httpS, so I want to exclude such URLs from that block.

That's why I added the second string to the code below, but it doesn't stop such URLs from applying RewriteRule ^ - [E=IS_HTTP:1]. Why?

#determine if page is supposed to be http
RewriteCond %{REQUEST_URI} !^administration [NC]
#if it has q=home or qq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(q=home|qq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]

Again, I want https://mydomain.com/administration/index.php and all other files from the folder /administration to be stopped before RewriteRule ^ - [E=IS_HTTP:1]
Why the code above does NOT stop them?

The second string I've tried was:

RewriteCond %{REQUEST_URI} !^administration [NC]
RewriteCond %{REQUEST_URI} !^/administration [NC]

but none of them works. (I believe / is not needed here as REQUEST_URI doesn't start from /, but I could be wrong).

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2025-01-12 15:23:42

而不是这种条件:

RewriteCond %{REQUEST_URI} !^administration [NC]

具有这种条件:

RewriteCond %{REQUEST_URI} !^/+administration [NC]

请记住,%{REQUEST_URI} 始终以斜杠开头,并且如果在浏览器中以这种方式键入,则可以有多个斜杠。

Instead of this condition:

RewriteCond %{REQUEST_URI} !^administration [NC]

have this condition:

RewriteCond %{REQUEST_URI} !^/+administration [NC]

Remember that %{REQUEST_URI} always starts with a slash and can have multiple slashes if it is typed that way in browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文