[英]how to redirect https://www.example.com/aaa to https://example.com/aaa/
[英]How to Redirect https://example.com/ to https://www.example.com/
我在.htaccess
文件中有此代码,如下所示。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
添加此选项是为了将http重定向到https,因此整个站点现在都是https版本。
现在我想从非www重定向到www。 当我输入example.com时,我应该被重定向到https://www.example.com/
如何使用.htaccess
文件执行此操作?
非SSL重定向:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L]
SSL重定向:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=permanent,L]
这个怎么样,因为https使用端口443
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
我可能有解决方案:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.[domain].com%{REQUEST_URI} [R=301,L,NE]
将[domain]和扩展名替换为您自己的域名。 告诉我,如果这不起作用。
将以下行放入.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]
为此,您必须从.htaccess文件中删除您在问题中提到的现有条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.