1

I need to redirect https://sampledomain.com.au OR https://www.sampledomain.com.au to http://www.sampledomain.com

So far this is my .htaccess condition but it's not working:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^sampledomain\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sampledomain\.com\.au$
RewriteRule (.*) http://sampledomain.com/$1 [R=301,L] 

What seems to be the problem/error? Thanks a lot :)

marknt15
  • 5,047
  • 14
  • 59
  • 67

3 Answers3

0

This single rule will meet both the requirements:

RewriteEngine On

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^sampledomain\.com\.au$ [NC]
RewriteRule ^ http://www.sampledomain.com%{REQUEST_URI} [R=301,L,NE] 
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hi @anubhava I tried your solution and it redirected to this one: https : // sampledomain.com.au/cgi-sys/defaultwebpage.cgi Not sure why is that happening. – marknt15 Mar 26 '15 at 06:30
  • That might be be due to your other rules and config. As you can see there is no reference to `cgi` here. Post your full .htaccess in question. – anubhava Mar 26 '15 at 06:32
  • I checked the .htaccess and there is no redirect to any "defaultwebpage.cgi". Maybe the website SSL is not legit, not existing or not properly configured? – marknt15 Mar 26 '15 at 06:43
  • SSL configuration cannot add `/cgi-sys/defaultwebpage.cgi`. It could be only due to some code/faulty rules. – anubhava Mar 26 '15 at 06:49
  • we'll try to buy an SSL certificate so that we'll have https then try to add an index.html or index.php so that if https: // sampledomain.com.au is accessed then index.html will be read then it will do the redirect hopefully to http://www.sampledomain.com – marknt15 Mar 30 '15 at 00:24
0

You better try this

    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvote if worked

Ujjwal
  • 519
  • 1
  • 5
  • 17
  • Hi @Ujjwal I tried your answer and got redirected to: https : // sampledomain.com.au/cgi-sys/defaultwebpage.cgi too – marknt15 Mar 26 '15 at 06:44
  • @marknt15 please search defaultwebpage.cgi on whole folder of you site.You may find the code. and remove if not necessary. – Ujjwal Mar 26 '15 at 07:06
0

The following finally solved problem for me:

Redirecting all https and/OR www requests to non-https and non-www and all its subdirectories.

https://sampledomain.com.au/           to http://sampledomain.com.au/

https://www.sampledomain.com.au/  to http://sampledomain.com.au/

http://www.sampledomain.com.au/    to http://sampledomain.com.au/

added to my .htaccess file:

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www.sampledomain.com.au [NC]
RewriteRule ^(.*) http://sampledomain.com.au/$1 [L,R=301]

Mind you, NOT escaping the "." with "\." in the RewriteCond

Worked on my shared hosting (escaping the "." with "\." did not work on my hosting, to my surprise)

Jürgen Fink
  • 3,162
  • 2
  • 23
  • 25