简体   繁体   English

.htaccess 重写规则,强制将 https 重定向到 http

[英].htaccess rewrite rule for forcefully redirect https to http

I have a primary domain https://www.domain.com or https://domain.com and a wildcard DNS like https://domain.com/index.php?name=abcd redirect on forcefully http://abcd.domain.com but I have another problem my login page is https://domain.com/login.php?name=abcd and I want result like forcefully http://domain.com/login.php?name=abcd but it cannot redirect on HTTP.我有一个主域https://www.domain.comhttps://domain.com和一个通配符 DNS,如https://domain.com/index.php?name=abcd强行重定向http://abcd.domain.com但我有另一个问题我的登录页面是https://domain.com/login.php?name=abcd并且我想要像强制http://domain.com/login.php?name=abcd这样的结果但是它不能在 HTTP 上重定向。

RewriteEngine On

#match either the www subdomain or no subdomain
  RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
#which request index.php
  RewriteCond %{REQUEST_URI}  ^/index\.php
#and contain a username paramater
  RewriteCond %{QUERY_STRING} ^(.*?)(?:^|&)name=([^&]+)(.*?)$
#then rewrite them to name.domain.com without the name parameter
  RewriteRule ^ http://%1.domain.com%{REQUEST_URI} [R,L]

#match either the www subdomain or no subdomain
  RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
#which was requested without https
  RewriteCond %{HTTPS} off
#then redirect to https
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]




#Capture subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)\.(?:domain\.com)$
#If we're not working on www
RewriteCond %{HTTP_HOST} !^(?:www.domain\.com)$
#If querystring doesn't contain name
RewriteCond %{QUERY_STRING} !^(.*?)(?:^|&)name=([^&]+)(.*?)$
#Add username to querystring
RewriteRule index.php index.php?name=%1 [L,QSA]

this htaccess code is working fine but i want login script in htaccess这个 htaccess 代码工作正常,但我想在 htaccess 中登录脚本


After clarification in chat, this is what I need:在聊天中澄清后,这就是我需要的:

All URLs should be rewritten to https , except login.php , which should stay at http .所有 URL 都应该重写为https ,除了login.php ,它应该保留在http If login.php comes in as https , rewrite it to http .如果login.phphttps ,请将其重写为http

You already have the rule for rewriting to https , the only thing left is excluding login.php你已经有了重写https的规则,唯一剩下的就是排除login.php

RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/login\.php$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

If login.php is requested with https , rewrite it to http如果使用https请求login.php ,则将其重写为http

RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
RewriteCond %{HTTPS} on
RewriteRule ^login.php$ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

Finally, a minor hint: never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.最后,一个小提示:永远不要在启用301测试,有关详细信息,请参阅此答案提示调试 .htaccess 重写规则

try this :尝试这个 :

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM