HTTP到HTTPS htaccess的重定向循环错误 [英] http to https htaccess redirect loop error

查看:352
本文介绍了HTTP到HTTPS htaccess的重定向循环错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我想完全从 HTTP 重定向到 HTTPS

我需要重定向通过 HTTP 到达现场,在同一页上 HTTPS 。<任何用户/ P>

该网站托管在一个供应商的共享主机。自安装域的SSL证书,一个新的IP地址已经被分配给该域

我已被告知,以下code应该被添加到我的的.htaccess 文件。也有一些规则,处理搜索引擎友好的URL。

  RewriteEngine叙述上
的RewriteBase /

#强制HTTPS和www
的RewriteCond%{} SERVER_PORT!= 443 [OR]
的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
重写规则^ HTTPS://www.example.com% {REQUEST_URI} [L,NE,R = 302]

#跳过进一步的规则文件和目录
的RewriteCond%{} REQUEST_FILENAME -D [OR]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则^  -  [L]

#内部重写规则
重写规则^([\ w  - ] +)/([\ w  - ] +)1 / $ page.php场地= $&放大器;?艺术家= $ 2 [L,QSA]
重写规则^([\ w  - ] +)?/ $ page.php场地= $ 1 [L,QSA]
 

由于某些原因,增加了这个$​​ C $ C到的.htaccess 文件,导致重定向循环错误。我已经试过了的RewriteCond%{} SERVER_PORT变种!= 443 行建议在其他堆栈溢出职位,但似乎没有任何工作。

有没有人有办法解决吗?

解决方案

您可以在您的根目录的.htaccess使用code:

  RewriteEngine叙述上
的RewriteBase /

#强制HTTPS和www
的RewriteCond%{HTTP:X-转发,SSL}上!
重写规则^ HTTPS://www.example.com% {REQUEST_URI} [L,NE,R = 302]

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

#跳过进一步的规则文件和目录
的RewriteCond%{} REQUEST_FILENAME -D [OR]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则^  -  [L]

#内部重写规则
重写规则^([\ w  - ] +)/([\ w  - ] +)1 / $ page.php场地= $&放大器;?艺术家= $ 2 [L,QSA]
重写规则^([\ w  - ] +)?/ $ page.php场地= $ 1 [L,QSA]
 

I have a site which I am trying to completely redirect from http to https.

I need to redirect any user that arrives at the site via http to the same page on https.

The site is hosted on a provider's shared hosting. Since the domain's SSL certificate was installed, a new IP address has been assigned to the domain.

I have been advised that the following code should be added to my .htaccess file. There are also some rules which handle SEO friendly URLS.

RewriteEngine On
RewriteBase /

# enforce https and www
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,NE,R=302]

# skip further rules for files and directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# internal rewrite rules
RewriteRule ^([\w-]+)/([\w-]+)/?$ page.php?venue=$1&artist=$2 [L,QSA]
RewriteRule ^([\w-]+)/?$ page.php?venue=$1 [L,QSA]

For some reason, the addition of this code to the .htaccess file, results in a redirection loop error. I have tried variants of the RewriteCond %{SERVER_PORT} !=443 line as advised on other Stack Overflow posts, but nothing seems to work.

Does anyone have a solution?

解决方案

You can use this code in your root .htaccess:

RewriteEngine On
RewriteBase /

# enforce https and www
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,NE,R=302]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]

# skip further rules for files and directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# internal rewrite rules
RewriteRule ^([\w-]+)/([\w-]+)/?$ page.php?venue=$1&artist=$2 [L,QSA]
RewriteRule ^([\w-]+)/?$ page.php?venue=$1 [L,QSA]

这篇关于HTTP到HTTPS htaccess的重定向循环错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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