[英].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.com
或https://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.php
以https
,请将其重写为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.