wordpress - 子域的 .htaccess 规则强制在所有页面上使用 https

标签 wordpress .htaccess ssl mod-rewrite

我有几个站点作为子域,主域称为 site1.com。我的主域有 *.site1.com 的通配符 ssl 证书。我的子域可以引用为 site2.site1.comsite3.site1.comsiteN.site1.com。我的主域正确使用证书并在所有页面上强制使用 https,我的子域仅在管理页面上使用 https,我使用的是 wordpress CMS,或者如果我将我的网站引用为 https,我可以强制使用证书://site2.site1.comhttps://site3.site1.com 等。我想让我的子域作为 https://site2.com 运行。目前我的域名是 http://site2.comhttp://site1.site2.com

PS:我无权访问 vhost 文件。这是我所有域的 .htaccess 代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# BEGIN WordPress

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

SetEnvIfNoCase User-Agent "^libwww-perl*"  block_bad_bots
Deny from env=block_bad_bots

</IfModule>

最佳答案

我找到了一个简单的插件来完成这项工作。这是我的子域的 .htaccess 文件现在的样子:

<IfModule mod_rewrite.c>
RewriteEngine on


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


# BEGIN WordPress

#RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*"  block_bad_bots
Deny from env=block_bad_bots
</IfModule>

关于wordpress - 子域的 .htaccess 规则强制在所有页面上使用 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40713134/

相关文章:

ssl - CNAMES 如何与 SSL 证书一起使用

php - 使用远程数据库、ubuntu、apache2 的本地 wordpress

php - 如何使用 jQuery (wordpress) 定位动态命名的元素 id

javascript - 如何在 jquery 中将链接转换为 seo 友好的 url

Golang TLS 握手错误 - "first record does not look like a TLS handshake"?

powershell - 如何在 Invoke-WebRequest 中显示 TLS 握手信息和 CONNECT 请求

wordpress - 尝试获取值时遇到这个简单代码的问题

php - 在 Wordpress 中更改动态页面的标题

.htaccess 使用 SSL/HTTPS 将 www 重定向到非 www

.htaccess RewriteRule 返回空白页