我有一些子域 s1.mywebsite.com
和 s2.mywebsite.com
。我正在尝试设置一个 URL 重写规则,以便将针对 mywebsite.com 的任何请求转换为 https,而对子域的请求保持不变。
现在在我的主域的根目录中,我有一个包含以下内容的 htaccess 文件:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule .* https://mywebsite.com/%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
那里有一些 wordpress 的内容。目前,我的服务器将请求 http://s1.mywebsite.com/page/
重写为 https://mywebsite.com/page/
完全消除了子域.如何让我的规则忽略子域查询?
最佳答案
添加条件以限制第一个 https->http
规则仅用于主域:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www\.)?mywebsite\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
关于apache - 使用 htaccess 规则在子域上进行不需要的 https 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31767487/