gpt4 book ai didi

.htaccess - 通过 htaccess 强制重定向到 https

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:27 26 4
gpt4 key购买 nike

我有域和子域,例如 example.com 和 blog.example.com,并在 bluehost 上使用通配符为两者启用了 ssl。我添加了 bluehost 建议的以下代码

自定义子域 .htaccess SSL + WordPress

    RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
# End custom subdomain .htaccess

# Custom maindomain .htaccess WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# End custom maindomain .htaccess

网站在 https 上正常运行,但也可以在 http 上访问。

我尝试了以下代码来强制重定向,但它不起作用。

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我还有两个主域和子域的 htaccess 文件,上面的代码放在主域 htaccess 文件中。

我是不是做错了什么或遗漏了什么来强制所有 url 使用 https://打开?

最佳答案

你试过这个吗:

仅针对域

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

对于子域(将 .htaccess 放在子域文件夹中)

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blog.example.com/$1 [R,L]

关于.htaccess - 通过 htaccess 强制重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34036067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com