使用htaccess的添加WWW以https支持htaccess、WWW、https

由网友(性凉怎暖Ta人心)分享简介:有很多code例子使用的.htaccess添加WWW到URL,但它们通常只限于使用HTTP。没有任何人有一个如何得到它在两种情况下工作的例子吗? There are a lot of code examples for using .htaccess to add www to a url but they are...

有很多code例子使用的.htaccess添加WWW到URL,但它们通常只限于使用HTTP。没有任何人有一个如何得到它在两种情况下工作的例子吗?

There are a lot of code examples for using .htaccess to add www to a url but they are usually confined to using http. does anybody have an example of how to get it to work in both cases?

推荐答案

肯定的:

RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

第二个条件会检查的 HTTPS 的环境变量(无论是关闭 )设置为并获取附加的取值中,然后可以用%1 。如果不匹配,%1 只是一个空字符串。

The second condition checks if the HTTPS environment variable (either on or off) is set to on and captures the appended s that is then available with %1. If it doesn’t match, %1 is just an empty string.

阅读全文

相关推荐

最新文章