如何将非WWW,非HTTPS重定向到WWW,没有多重重定向的HTTPS?

时间:2015-05-19 08:02:39

标签: .htaccess redirect https

我希望你能帮助解决这个htaccess问题吗?我基本上将htaccess规则与一个场景分开。这是用户在非HTTPS和非WWW链接上访问该站点的情况。

重新定向

  1. 用户访问http /非WWW网址
  2. 用户最初被重定向到http / WWW URL
  3. 然后将用户重定向到https://www.website
  4. 您可以在此处查看此行为:

    http://childrens-curtains.co.uk

    所有其他方案都可以正常使用。

    我想尝试从序列中删除第二个重定向,使其行为如下:

    用户访问http并立即重定向到https / www版本而没有第二步(如果有意义的话)?

    当前场景会导致多个重定向,从SEO的角度来看,我理解这是一个糟糕的方法。

    这是我的htaccess重定向规则:

    RewriteEngine On
    # This will enable the Rewrite capabilities
    
    RewriteCond %{HTTPS} !=on
    # This checks to make sure the connection is not already HTTPS
    
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [L,R=301]
    # This rule will redirect users from their original location, to the same location but using HTTPS.
    # The leading slash is made optional so that this will work either in httpd.conf
    # or .htaccess context
    

1 个答案:

答案 0 :(得分:0)

您可以尝试将此代码保存到.htaccess文件中。

添加www添加以下代码。

RewriteCond %{HTTP_HOST} ^**domainname**\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domainname\.com$
RewriteRule ^index\.html$ "http\:\/\/www\.domainname\.com\/" [R=301,L]

添加http添加以下代码。

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

将http和www添加到URL。

感谢。

相关问题