apache - 使用 htaccess 规则在子域上进行不需要的 https 重定向

标签 apache .htaccess mod-rewrite ssl

我有一些子域 s1.mywebsite.coms2.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/

相关文章:

php - 来自 pcntl_fork 的进程未终止

.htaccess AuthType 基本文件匹配 401 和 403 的除 Maintenance.html 之外的所有文件

php - .htaccess 不适用于 Apache2

mod-rewrite - %2 的 RewriteCond 变量反向引用

apache - 重写规则以在 HTTP 和 HTTPS 上工作

apache - vue项目中如何将所有www流量重定向到非www网址

apache - 重定向到 www 会导致一秒钟的延迟吗?

apache - Docker 错误 : Cannot create container for service web: invalid mode

php - include_path fatal error xampp

php - 如何从codeigniter项目中的url中删除index.php