apache .htaccess 文件 https:// 重定向 ---- 将其重写为子目录?

发布于 2024-10-31 02:32:05 字数 296 浏览 0 评论 0原文

这是我的代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

如果我将其放入主目录的 .htaccess 文件中,这将成功地将所有内容重写为 https(它将“强制”https)。但是,如果我只想让 /support 的子目录强制使用 https,该怎么办?如何重写上面的代码?

目的是在 WHMCS 中强制使用 https

提前致谢!

here is my code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This will successfully rewrite everything to https (it will "force" https), if I put it in my home directory's .htaccess file. However, what about if I only want my subdirectory of /support to force https? How to rewrite the above code?

The intent is with regards to forcing https in WHMCS

Thanks in advance!

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

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

发布评论

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

评论(2

对岸观火 2024-11-07 02:32:05

如果您只想重定向子文件夹而不是子域,那就更容易了。要重定向子文件夹 /support/,您将使用以下代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/support/(.*)$ https://%{HTTP_HOST}/support/$1 [QSA]

我添加了一个 QSA 标志,这将强制输入的任何查询字符串附加到重定向 URL。如果您不在网站的此部分中使用查询字符串,则可以删除该标志。另外,如果所示的字符串不起作用,您可以尝试从 RewriteRule 中删除前导斜杠并重试。

If you want to redirect only a subfolder and not a subdomain, that is even easier. To redirect the subfolder /support/ you would use the following code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/support/(.*)$ https://%{HTTP_HOST}/support/$1 [QSA]

I added a QSA flag, which will force any query string that was entered to be appended to the redirect URL. If you don't use query strings in this section of the site, you can remove that flag. Also, if the string as shown doesn't work, you can try removing the leading slash from the RewriteRule and retrying it.

柠檬 2024-11-07 02:32:05

在 %{HTTPS} 行之前添加以下规则:

RewriteCond %{HTTP_HOST} ^support.domain.com$

这将仅允许在访问者来自子域时执行规则。请注意,这些规则可能需要放入子域根目录的 .htaccess 文件中,而不是主站点根文件夹中。

Add the following rule before the %{HTTPS} line:

RewriteCond %{HTTP_HOST} ^support.domain.com$

This will only allow the rule to execute if the visitor is coming from the subdomain. Please note, these rules will likely need to be put in the .htaccess file that is the root for the subdomain, not the main site root folder.

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