How to auto redirect http to https urls

Miyukichii

Aspirant
Joined
Sep 2, 2018
Messages
15
Hi! i know you can do it within .htaccess but what would be the right url that would automatically redirect http to https urls ?
 

BirdOPrey5

#Awesome
Joined
Aug 14, 2008
Messages
4,217
The question, as posed, doesn't make sense. It wouldn't be a URL but a rewrite rule that would do the redirect. As for Rewrite Rule there are many options and many examples if you Google the question "How to automatically redirect to https with htaccess"

Some very basic code to do it would be:

Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
But there are all types of examples this was just the first one from: https://serverguy.com/servers/redirect-http-to-https/
 

we_are_borg

Administrator
Joined
Jan 25, 2011
Messages
5,522
If you have Plesk or cPanel then you should be able to do this from the panels easier to maintain.
 

Miyukichii

Aspirant
Joined
Sep 2, 2018
Messages
15

Miyukichii

Aspirant
Joined
Sep 2, 2018
Messages
15
The question, as posed, doesn't make sense. It wouldn't be a URL but a rewrite rule that would do the redirect. As for Rewrite Rule there are many options and many examples if you Google the question "How to automatically redirect to https with htaccess"

Some very basic code to do it would be:

Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
But there are all types of examples this was just the first one from: https://serverguy.com/servers/redirect-http-to-https/
Edit: nvm :) this works !! for the forum

I tried to do this for my homepage as well but i received an error:

Permission denied.
Error code: 3
Error message from server: Permission denied
 

BirdOPrey5

#Awesome
Joined
Aug 14, 2008
Messages
4,217
Is the code in the .htaccess file of the root (top level) directory like www or public_html? If so you may need to ask your host the best way to redirect traffic.
 

PoetJC

⚧ Jacquii: Kween of Hearts ⚧
Joined
Jul 9, 2006
Messages
21,043
The code I use is as follows and also rewrites the deprecated www. out of the url too:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://sitename.com%{REQUEST_URI} [R=301,L]
HTH,

J.
 

BirdOPrey5

#Awesome
Joined
Aug 14, 2008
Messages
4,217
The code I use is as follows and also rewrites the deprecated www. out of the url too:
Whether one uses the www or not is a separate matter, if they choose not to use it they need to make sure their forum URL in setting matches their choice.

As for it being "depreciated" someone should tell Google: https://www.google.com/
 

Miyukichii

Aspirant
Joined
Sep 2, 2018
Messages
15
The code I use is as follows and also rewrites the deprecated www. out of the url too:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://sitename.com%{REQUEST_URI} [R=301,L]
HTH,

J.
This rule works great !! for the forum, i am having issues with my custom made homepage though, so i will look into it more later.
 

PoetJC

⚧ Jacquii: Kween of Hearts ⚧
Joined
Jul 9, 2006
Messages
21,043
Whether one uses the www or not is a separate matter, if they choose not to use it they need to make sure their forum URL in setting matches their choice.

As for it being "depreciated" someone should tell Google: https://www.google.com/
Well... The issue I had with one forum was that people were logging into the site via www.site.com as opposed to simply site.com and this caused a bit of an issue with users being logged out of the forum. Even though the settings were set to site.com - It seems that their browsers recognized www.site.com and site.com as two different properties. We implemented the above .htaccess code and the issue was instantly resolved because the code routes all users to https://site.com and disallows the www ... which I suppose in my opinion is deprecated as all sites begin with it, unless you're accessing ftp, DNS or some other service/application.

There are plenty of arguments/debates on google as to whether www. is deprecated.
Many say yes it is. But I do wonder -- since you brought it up -- whether Google has any specific comment as for the to use www. or not to use www. debate.

This rule works great !! for the forum, i am having issues with my custom made homepage though, so i will look into it more later.
Glad the code worked for you!
Cheers ;)

Its not deprecated, some just choose not to use it, either way is perfectly fine.
LOL. Well... There are plenty of arguments on both sides as stated above.
Perhaps one day there will be an "official" clarification from the "powers that be" - so the debate can finally be ended.
Until then though = I'm of the no www. camp. And implementing the code I shared earlier has sorted all sorts of issues I've had on various forums and websites with the sort of disconnect between using www. and not using it. So .... Yeah... A dose of clarification needed immediately LOL

J.
 

PoetJC

⚧ Jacquii: Kween of Hearts ⚧
Joined
Jul 9, 2006
Messages
21,043
i am having issues with my custom made homepage though
And oops Miyukichii - I did mean to also say welcome to TAZ.
About the issue with your homepage though: what sort of issue are you having? Perhaps someone here can offer a fix for it...

J.
 

Tracy Perry

Opinionated asshat
Joined
May 25, 2013
Messages
4,991
It seems that their browsers recognized www.site.com and site.com as two different properties.
Actually what happened (if using XenForo) is it was using 2 different cookies - each domain has it's own and would cause you to be logged out if switching between the two. ;)
For sites like WordPress, etc. (blogs and stuff) it really doesn't matter if it's not writing a cooking for login credentials.

On the WWW vs non-WWW.... it's usually stripped because it's 4 less characters to type if manually entering the address now. Basically a time saver. Back in the day WWW served a purpose as an end-user designator for web based access - but now it's just a time waster. That was in the days you also had ftp.whatever.com, smtp.whatever.com, and several other service designators. It's not as important in MOST cases now. Used to you wanted your MX servers to have mx1.whatever.com, mx2.whatever.com but now people use standard domain names frequently for their MTA.
 

PoetJC

⚧ Jacquii: Kween of Hearts ⚧
Joined
Jul 9, 2006
Messages
21,043
Actually what happened (if using XenForo) is it was using 2 different cookies - each domain has it's own and would cause you to be logged out if switching between the two. ;)
For sites like WordPress, etc. (blogs and stuff) it really doesn't matter if it's not writing a cooking for login credentials.
Yup. The XF install had an issue with different cookies being served. The only way I found of solving the issue was to implement the .htaccess code. There are probably other ways to maybe *better* fix the issue - but the .htaccess code worked and no further issues after that.

A similar thing happened on a WP install that was using WooCommerce as their eCommerce solution, where the a logged in user would be logged out if using the www. prefix. Again - implementing the .htaccess code fixed the issue.

Anyway = Thanks for sharing that technical info Tracy Perry.

J.
 

Tracy Perry

Opinionated asshat
Joined
May 25, 2013
Messages
4,991
There are probably other ways to maybe *better* fix the issue - but the .htaccess code worked and no further issues after that.
Nope, that is the best way. Serving the site from a consistent domain resolves the issue.

WP install that was using WooCommerce as their eCommerce solution
Anything that uses cookies to track login related info will suffer from it typically as they are realistically two entirely different domains (actually one TLD and then a sub-domain). For WordPress I was referring to when you simply visit the blog. If logging in it will probably also have similar issues.
 

BirdOPrey5

#Awesome
Joined
Aug 14, 2008
Messages
4,217
Well... The issue I had with one forum was that people were logging into the site via www.site.com as opposed to simply site.com and this caused a bit of an issue with users being logged out of the forum. Even though the settings were set to site.com - It seems that their browsers recognized www.site.com and site.com as two different properties.
This isn't at you directly PoetJC just for anyone interested more in the why...

They recognized them as two different properties because they are two different properties as websites work and especially for JavaScript security. You don't want JavaScript from one site being able to affect another. Cookies also but those can be more forgiving if set right which was an option VB3/VB4 offered (that in my opinion it shouldn't) the custom cookie domain / cookie path settings.

So while you could get away with www and non-www working on VB3 and VB4 sites doing so is bad practice. Most importantly Google and other search engines will be indexing both versions of your site- to search engines the www and non-www URLs are different sites.

In short, forcing www or non-www is the best solution via an .htaccess file or other rule (depending on server type) but it is most certainly a personal preference (or in some instances a technical requirement.)
 
Top