繁体   English   中英

htaccess使用子域和https重定向

[英]htaccess redirects with subdomains and https

我正在使用托管两个域(都使用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.comhttps://www.site2.com重定向到https://site2.com

试试这个代码:

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /~hostgatorusername/

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^dev\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]

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

# END WordPress

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM