将https服务的所有数据重定向到http [英] Redirect all the data served by https to http

查看:167
本文介绍了将https服务的所有数据重定向到http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这里是这样的情况:



我们正在运行一个由 Drupal的。前段时间,决定将该网站作为SSL。将网站从http重定向到https的设置是由一个不在我们身上的人完成的。



我可以在 .htaccess 中看到以下行

  #Redirect http到https 
RewriteEngine On
RewriteCond%{SERVER_PORT} 80
RewriteRule ^(。*)$ https:// docs .dev.domain.com / $ 1 [R,L]

mydomain.com指向根LAMPP服务器和我的网站位于webroot(docs.dev.domain.com/mysite)中的文件夹中。



现在,已经确定SSL是不需要,它必须被删除,所有的页面都必须通过http(301重定向)来提供。



当我使用.htaccess文件中的code> RewriteRule 重定向网址(例如 https: //docs.dev.domain.com/mysite/content/book )当http用户访问https时,使用以下方式:http:/// $ p

  RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_URI}!= / favi con.ico
RewriteRule ^ index.php [L]


#Redirect HTTPS到HTTP
RewriteCond%{SERVER_PORT} ^ 443 $
#RewriteCond %{HTTPS} on
RewriteRule ^(。*)$ http://docs.dev.domain.com/mysite/$1 [R = 301,L]
#even尝试了 - RewriteRule ^( 。*)$ http://docs.dev.domain.com/$1 [R = 301,L]

,但它会将https上的每个请求重定向到 http://mydomain.com/mysite/index.php (甚至网址(https://docs.dev.domain.com/mysite/content/book/1)应该理想地被重定向到其 http 对应的URL )。



如何删除https,以便我的动态网址通过普通的http?
对不起,如果这是非常新手的问题。

解决方案

这是因为在重定向之前有路由规则。重写引擎将循环,直到URI恢复不变,此时,它将评估URI是否需要传递到其他模块以便处理重定向或代理。



这意味着你的请求被路由到 index.php ,然后重写引擎循环,然后它看到该请求(在这一点上简单地是 /index.php )需要重定向,所以请求被标记为重定向。然后mod_rewite重定向,但到目前为止,您的路由规则被破坏了。



您需要交换顺序:


$ b $在
RewriteRule ^(。*)$ http://docs.dev.domain.com/mysite/$1 [R = 301,...,$ pre> RewriteCond%{HTTPS} L]

RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_URI}!= / favicon.ico
RewriteRule ^ index.php [L]


So, here is the situation:

We are running a website which is powered by Drupal. Sometime ago, it was decided that the website should be served as SSL. The settings to redirect the site from http to https was done by a guy who is not with us anymore.

I can see in the .htaccess file the following lines

#Redirect http to https
RewriteEngine On  
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://docs.dev.domain.com/$1 [R,L]

mydomain.com points to the root of the LAMPP server and my site is in a folder inside the webroot (docs.dev.domain.com/mysite).

Now, it has been decided that the SSL is not needed and it has to be removed and all the pages must be served via http (301 redirect).

When I do that in the .htaccess file by using the RewriteRule to redirect a URL (e.g. https://docs.dev.domain.com/mysite/content/book) to http when a user visits https by using:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]


#Redirect HTTPS to HTTP
RewriteCond %{SERVER_PORT} ^443$
#RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://docs.dev.domain.com/mysite/$1 [R=301,L]
#even tried this - RewriteRule ^(.*)$ http://docs.dev.domain.com/$1 [R=301,L]

but it redirects every request on https to http://mydomain.com/mysite/index.php (even the urls like (https://docs.dev.domain.com/mysite/content/book/1 which should ideally be redirected to its http counterpart).

How can I remove the https so that my dynamic URLs are served via plain http? Sorry if this is very novice problem.

解决方案

This is happening because you have a routing rule before the redirect. The rewrite engine will loop until the URI comes back unchanged, and at that point, it evaluates if the URI needs to be passed onto other modules in order to handle redirecting or proxying.

That means your request is getting routed to index.php, then the rewrite engine loops, then it sees that the request (which at this point is simply /index.php) needs to be redirected, so the request gets flagged to be redirected. Then mod_rewite redirects, but by now, the URI is mangled by your routing rule.

You need to swap the order:

RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://docs.dev.domain.com/mysite/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

这篇关于将https服务的所有数据重定向到http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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