【发布时间】:2014-01-25 20:30:34
【问题描述】:
我正在使用托管两个域(均使用 SSL)的 HostGator 帐户。我还在这两个上都设置了不使用 SSL 的子域。我设置了重定向,以便 http 将重定向到 https,但我在处理子域时遇到问题。
这是我需要它做的事情:
http://site1.com -> https://site1.com
http://www.site1.com -> https://site1.com
dev.site1.com -> 无重定向
http://site2.com -> https://site2.com
http://www.site2.com -> https://site2.com
dev.site2.com -> 无重定向
现在发生的事情是,当我访问 dev.site2.com(无论我是否输入 https)时,我看到的是 https://site1.com,尽管它似乎没有重定向,因为地址栏仍然显示 dev.site2.com
这是我在 htaccess 中的内容:
RewriteEngine On
RewriteBase /~hostgatorusername/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} !=dev.*
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~hostgatorusername/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~hostgatorusername/index.php [L]
</IfModule>
# END WordPress
我仍在尝试完全掌握 htaccess,所以如果有人可以帮助我了解我做错了什么,我会很高兴。谢谢!
更新:我还需要 https://www.site1.com 重定向到 https://site1.com 和 https://www.site2.com 重定向到https://site2.com
【问题讨论】:
-
!=dev.*不是一个有效的正则表达式,除非你有一个 http 主机,它的名称中确实有一个=。=不是正则表达式中的相等测试,它只是一个像 a 或 P 或 3 这样的字符 -
谢谢。我不太擅长正则表达式。
标签: apache .htaccess mod-rewrite ssl subdomain