setup ssl and http redirect to https - redirect

Hi im hosting my site in bluehost, I have a problem with http to https redirect. I tried to create a redirect in htaccess and I get a redirect loop. When I remove my htaccess redirect and tried to put https://mysite.com I think it redirects me to http. But I can't seem to find where did that redirect happens, is it possible that it is because of dns record?
UPDATE:
also how can I put the padlock instead of the blank white paper in the browser url.

Try the following:
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Here, we set all visiting browsers to WWW.domainname.ext
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Good luck! I hope this solves your problem.
If there is an A-record on www.yourdomain.com, it will overrule your HTACCESS.

Related

"There was an error adding the redirect. Redirecting will cause a redirection loop"

I am getting this error in cpanel in the Add Redirect section after creating an add-on domain:
There was an error adding the redirect. Redirecting "https://example.com"
will cause a redirection loop because "http://.*/", which is located at
"/home/folder/", is above "https://example.com", which is located at
"/home/folder/"
Type = Permanent (301) redirection
All Public Domains
Redirects to: "https://addonDomain"
Wild Card Redirect
Preferably through cpanel, the goal is to redirect only through 301 redirect, for SEO purposes, and redirect the primary domain to the add-on domain. How to fix this loop? Thanks!
You can use via .htaccess
Edit with this code:
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301,NC]
Change yourdomain.com with your domain name. This work for me.

Prevent SSL for addon domains

I'm sure someone would have asked this question earlier, but i wasnt able to find a correct answer yet.
I have a primary domain www.domain.com and 2 addon domains www.domain1.com and www.domain2.com, all these were working fine till when I installed a SSL for the primary domain.
I have a redirect .htaccess as follows
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
With this, i see the addon domain URL's as follows
https://www.domain.com/domain1/ or /domain2/
Can anyone please guide me on how to get back to
www.domain1.com for my addons..?
your help is highly appreciated.
Thank you,
Abilash
I was able to disable SSL on my addon domain by putting the following code to the end of the .htaccess
RewriteCond %{HTTPS} on
RewriteRule ^(home|help)(.*)/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
And it worked!

Redirect www to non-www if subdomain

My domain http://vietnam.asiastreetfood.com works fine. But if somebody calls http://www.vietnam.asiastreetfood.com theres an error. I cannot enter www.vietnam as a subdomain at 1und1.de. So any ideas how i can redirect the www to the non-www domain?
This is what i tried:
RewriteCond %{HTTP_HOST} ^www\.vietnam.asiastreetfood\.com [NC]
RewriteRule (.*) http://vietnam.asiastreetfood.com/$1 [R=301,L]
I think that 'www' is technically a subdomain itself or at least a prefix not generally used with a "sub-domain", so in order to get www.sub.domain.com you have to configure a vhost on the server (much more complicated than an htaccess). Here is a Media Temple article I found as a starting point.
But this won't be possible on 1und1.de - you will have to contact their support and see if they can configure this (unlikely).

How to solve a WWW/NonWWW Header Check: FAILED

I ran a duplicate checker for my website and got the following message
WWW/NonWWW Header Check: FAILED Your site is not returning a 301
redirect from www to non-www or vice versa. This means that Google may
cache both versions of your site, causing sitewide duplicate content
penalties.
Is this something that i should be worried about and if so how should i fix it ?
You shouldn't be worried about it, allot of sites are configured that way and google knows that.
However you can still add this if you want to be safe and send your visitors and google always go to example.com instead of www.example.com
Add this to your .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

301 redirect and /index.php

i made a grave mistake with my site. i didn't check the difference between .www and non .www so the one that had the www in it was a little broken.
well anyways i've plugged a 301 redirect in here, and for http://mysite.com it's fine as usual, but the http://www.mysite.com now adds on /index.php. that can't be the best for SEO, right? (the cms is Textpattern if that is relevant)
another problem this redirect code has is: http://www.mysite.com/blog will take you back to the homepage.
what do you think?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
i seem to have found the problem. i think that 301 script has to be at the top of the .htaccess document or it will cause problems. such as the blog problem and the /index.php inconsistency.