将https非www域转换为https www

时间:2016-04-19 10:37:18

标签: wordpress .htaccess

我想自动从example.com重定向到www.example.com

这是我的wordpress htaccess代码.....

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.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

3 个答案:

答案 0 :(得分:2)

RewriteEngine On
RewriteCond %{HTTPS_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]

从现在开始,当有人访问https://yourdomain.com时,他/她将被重定向到https://www.yourdomain.com

答案 1 :(得分:0)

转换

您可以使用以下规则:

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]

如果您确定规则工作正常,只需将 R 更改为 R = 301

答案 2 :(得分:0)

这可能对您有所帮助:

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

它会在您的域中自动添加www。

例如:https://fastassignmenthelp.co.uk/https://www.fastassignmenthelp.co.uk/