[英]Wordpress multisite Force HTTPS and WWW for domain and only HTTPS for subdomains HTACESS
I currently have a wordpress multisite setup of that consist of two sites, one is a subdomain. 我目前有一个wordpress多站点设置,包括两个站点,一个是子域。 lets call the main domain www.domain.com and the sub domain test.domain.com
我们可以调用主域名www.domain.com和子域名test.domain.com
The main issue I am having is when I enter https://test.domain.com this will work correctly but when I type in http://test.domain.com I get redirected to https://www.domain.com which is the main website and not the subdomain website. 我遇到的主要问题是,当我输入https://test.domain.com时,这将正常工作,但当我输入http://test.domain.com时,我被重定向到https://www.domain.com这是主要的网站,而不是子域名网站。
<IfModule mod_rewrite.c>
RewriteEngine On
# for subdomains
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(test\.domain\.co)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
# for main domains
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^domain\.co$ [NC]
RewriteRule ^.*$ https://www.domain.co%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
For the subdomain, you can use this rule : 对于子域,您可以使用此规则:
# for subdomains
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(test\.example\.com)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
Ok so I found the reason why I always redirected to the https version. 好的,我找到了我总是重定向到https版本的原因。 I had originally setup the apache server to use a virtual hosts.
我最初设置apache服务器以使用虚拟主机。 In that file for all http request or rather port 80 eg
<VirtualHost *:80>
I had stupidly created a redirect rule of Redirect permanent / https://maindomain.co/
在所有http请求的文件中,或者更确切地说是端口80,例如
<VirtualHost *:80>
我愚蠢地创建了Redirect permanent / https://maindomain.co/
的重定向规则Redirect permanent / https://maindomain.co/
I resolved this issue by removing that redirect and letting my .htaccess file manage the redirects. 我通过删除重定向并让我的.htaccess文件管理重定向来解决了这个问题。 It now works beautifully.
它现在很漂亮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.