Reputation: 161
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.
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
After clarification in chat, this is what I need:
All URLs should be rewritten to https
, except login.php
, which should stay at http
. If login.php
comes in as https
, rewrite it to http
.
Upvotes: 1
Views: 950
Reputation: 74028
You already have the rule for rewriting to https
, the only thing left is excluding 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
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.
Upvotes: 1
Reputation: 265
try this :
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
Upvotes: 0