1

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.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
Amy
  • 161
  • 1
  • 10
  • I read your .htaccess, but I don't understand what you want to achieve. What do you mean with "I want login script in htaccess"? – Olaf Dietsche Sep 29 '15 at 11:09
  • i want to say i want this result http://domain.com/login.php?name=abcd my domain is https so its automatically redirect to https – Amy Sep 29 '15 at 11:37
  • And at what input do you want `/login.php?name=abcd`? Is it where you have `index.php` now or in addition to it or maybe something else? – Olaf Dietsche Sep 29 '15 at 12:13
  • index.php is also in same directory – Amy Sep 29 '15 at 12:17
  • I still don't understand, *when* you want to see `login.php`. What should be the URL or condition to redirect to `login.php`? – Olaf Dietsche Sep 29 '15 at 12:44
  • ok i will telling you clearly in chat – Amy Sep 29 '15 at 12:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90889/discussion-between-amy-and-olaf-dietsche). – Amy Sep 29 '15 at 12:45

2 Answers2

1

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.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

try this :

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
Nero
  • 265
  • 1
  • 3
  • 12
  • where should i add these lines – Amy Sep 29 '15 at 09:43
  • Just add to your site's vhost_ssl.conf configuration (or .htaccess at the root of the site) – Nero Sep 29 '15 at 09:46
  • this line means all of the url redirect on http but i want only login.php redirect on http – Amy Sep 29 '15 at 09:48
  • maybe try something like this `RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} login.php RewriteRule ^(.*)$ https://www.example.com/folder/login.php$1 [R,L]` – Nero Sep 29 '15 at 10:05