重定向非www和非HTTPS访问https:// WWW [英] Redirect non-www and non-https to https://www

查看:250
本文介绍了重定向非www和非HTTPS访问https:// WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向非www和非HTTPS URL以的https:// WWW 我的域,我居然有以下htaccess的,这工程确定重定向非-https到https,但仍允许访问 domain.com 加www,

  RewriteEngine叙述上
的RewriteCond%{} HTTPS!=上
。重写规则* https://开头%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R]

#重定向结尾的斜杠...
重写规则^(。*)/ $ / $ 1 [L,R = 301]

#拉手前端控制器...
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]
 

我发现我应该使用以下方法来强制WWW,但我不能得到它应该放在最佳,谢谢

 的RewriteCond%{HTTP_HOST}!^ WWW。 [NC]
的RewriteCond%{HTTP_HOST} ^(。+)$ [NC]
重写规则^(。*)$ HTTP://www.%1/$1 [R = 301,L]
 

解决方案

您可以使用:

  RewriteEngine叙述上

的RewriteCond%{} HTTPS关闭[OR]
的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
重写规则^ HTTPS://www.domain.com% {REQUEST_URI} [R = 301,L,NE]

#删除结尾的斜杠...
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{THE_REQUEST} \ S(。+?)/ +?\ S]
重写规则^(。+?)/ $ / $ 1 [R = 301,L,NE]

#拉手前端控制器...
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]
 

I want to redirect non-www and non-https URLs to https://www for my domain, I actually have the following htaccess, that works ok redirecting non-https to https but still allows to access domain.com without www,

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R]

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I've found I should use the following to force www, but I can't get where it should be placed for best, thanks

RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

解决方案

You can use:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

# Remove Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L,NE]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

这篇关于重定向非www和非HTTPS访问https:// WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆