htaccess 从重写规则中排除 1 个文件夹
根据我的值 IS_HTTP,我在下面的代码之后决定 URL 应该是 https 还是 http。
我希望 http://mydomain.com
始终使用 http(从 https 重定向)(有一个空的 QUERY_STRING),http://mydomain.com/?q=home
,http://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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是这种条件:
具有这种条件:
请记住,
%{REQUEST_URI}
始终以斜杠开头,并且如果在浏览器中以这种方式键入,则可以有多个斜杠。Instead of this condition:
have this condition:
Remember that
%{REQUEST_URI}
always starts with a slash and can have multiple slashes if it is typed that way in browser.