[英]How to Redirect https://example.com/ to https://www.example.com/
I have this code in my .htaccess
file as shown below. 我在
.htaccess
文件中有此代码,如下所示。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This was added to redirect http to https so the entire site is now in https version. 添加此选项是为了将http重定向到https,因此整个站点现在都是https版本。
Now I want to redirect from non-www to www. 现在我想从非www重定向到www。 When I type example.com I should be redirected to https://www.example.com/
当我输入example.com时,我应该被重定向到https://www.example.com/
How do I do that with an .htaccess
file? 如何使用
.htaccess
文件执行此操作?
Non-SSL redirection: 非SSL重定向:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L]
SSL redirection: SSL重定向:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=permanent,L]
How about this as https uses port 443 这个怎么样,因为https使用端口443
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I might have the solution: 我可能有解决方案:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.[domain].com%{REQUEST_URI} [R=301,L,NE]
Replace [domain] and the extension to your own domain. 将[domain]和扩展名替换为您自己的域名。 Tell me if this doesn't work.
告诉我,如果这不起作用。
Put the following lines in to your .htaccess file and replace mydomain.com
with the domain that you want to redirect. 将以下行放入.htaccess文件中,并将
mydomain.com
替换为要重定向的域。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.){0,1}mydomain.com$ [OR]
RewriteCond %{HTTPS_HOST} ^(www\.){0,1}mydomain.com$
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
For this to work you will have to remove the existing entries that you mention in your question from the .htaccess file 为此,您必须从.htaccess文件中删除您在问题中提到的现有条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.