htaccess to redirect http:// and http://www to https:// that plays nice with subdomains

放肆的年华 提交于 2019-12-04 12:43:28

You can have your .htaccess like this:

RewriteEngine On
RewriteBase /

#subdomain 1
RewriteCond %{HTTP_HOST} ^sub1.mydomain.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/sub1/$1 [R=301,L]

#subdomain 2
RewriteCond %{HTTP_HOST} ^sub2.mydomain.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/sub2/$1 [R=301,L]

#get rid of www, works with rackspace cloud sites
RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

#force https, works with rackspace cloud sites
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

PS: Note that the HTTPS server variable is not correctly implemented in a Rackspac Cloud Environment. The correct variable to look at for HTTPS in Rackspace Cloud is ENV:HTTPS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!