.htaccess中 - 从http重写到HTTPS和WWW到非www [英] Htaccess - Rewrite from http to https and www to non-www

查看:195
本文介绍了.htaccess中 - 从http重写到HTTPS和WWW到非www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写形式HTTP到HTTPS和WWW到非www的网址。

基本上,如果有人去 http://www.example.com 他们需要被重定向到<一个HREF =htt​​ps://example.com相对=nofollow> https://example.com 与错网址的所有其他实例(的 http://example.com ,等等)。

我试图拼凑起来的建议要做到这一点:

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} HTTPS!上
重写规则HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI}
的RewriteCond%{HTTP_HOST} ^ WWW \ .garrysun \ .COM [NC]
重写规则^(。*)$ https://garrysun.com/$1 [L,R = 301]
 

但是,当我在一个重定向检查查询的网址我得到的错误...... http://garrysun.com 作品细并进入 https://garrysun.com 不过的 http://www.garrysun.com 得到这样的:

选中链接: http://www.garrysun.com 重定向类型:301永久移动 重定向到: https://garrysun.com/https://www.garrysun.com

我怎样才能纠正我重写code?

P.S。 - 我使用OpenCart 1.5.4和我也有以下重写code以上的新的东西(不知道这是否会影响任何东西):

 重写规则^ sitemap.xml的$的index.php?路径=进/ google_sitemap [L]
重写规则^ googlebase.xml $的index.php?路径=进/ google_base [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} * \!。(ICO | GIF | JPG | JPEG | PNG | JS | CSS)
重写规则^([^] *)的index.php?_route _ = $ 1 [L,QSA]
 

解决方案

您可以使用此单一规则的要求:

  RewriteEngine叙述上
的RewriteBase /

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

#休息你的规则将在下面出现
 

I am trying to rewrite form http to https and www to non-www urls.

Basically if someone goes to http://www.example.com they need to be redirected to https://example.com and all other instances of wrong urls (http://example.com, etc.).

I tried to do this by piecing suggestions together:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.garrysun\.com [NC]
RewriteRule ^(.*)$ https://garrysun.com/$1 [L,R=301]

But when I check the URL in a redirect checker I get errors... http://garrysun.com works fine and goes to https://garrysun.com but http://www.garrysun.com gets this:

Checked link: http://www.garrysun.com Type of redirect: 301 Moved Permanently Redirected to: https://garrysun.com/https://www.garrysun.com

How can I correct my rewrite code?

P.S. - I am using OpenCart 1.5.4 and I also have the following rewrite code above the new stuff (don't know if it affects anything):

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

解决方案

You can use this single rule for that requirement:

RewriteEngine On
RewriteBase /

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

# rest of your rules will appear below

这篇关于.htaccess中 - 从http重写到HTTPS和WWW到非www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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