HTTPS rewrites .htaccess - .htaccess

I have just had an SSL certificate installed to my site.
It was installed to the subdomain.
I have a rewrite on the sub domain so http://orderonline.mydomain.com.au uses web servers from the same server but in another account. This rewrite work fine.
RewriteCond %{SERVER_PORT} 80
RewriteRule ^orderonline/?$ http://111.67.13.129/~dsoft/themes/RIV00/
However I can't seem it work with the https. The https is directed to the subfolder 'orderoline'.
How do I do a rewrite for the https to point to http://111.67.13.129/~dsoft/themes/RIV00/ but still maintain https//orderonline.mydomain.com.au.
Thanks in advance
Daniel

I worked it out.
I needed to change
RewriteCond %{SERVER_PORT} 80
to
RewriteCond %{SERVER_PORT} 443
However is it possible to do both?
d

Related

website keeps redirecting to HTTP

i have just installed my SSL wich i have bought on transip.nl
When i take a look at the website which i have installed for it looks like its not going well.
i have checked : https://www.sslshopper.com/ssl-checker.html#hostname=sloffenenpantoffels.nl
Looks fine but its not. there is no safe logo and he is still telling its an unscure connection.
When i check the URL its HTTP and not HTTPS.
Webshops is build in a magento multistore.
I have made own domain and selected his own IP for the SSL. I pointed the root folder to the folder from the main domain of the multistore.
In my htaccess file there is a rule:
RewriteCond %{HTTP_HOST} ^(.*)sloffenenpantoffels.nl
RewriteRule ^ - [E=MAGE_RUN_CODE:ditwiljehebben]
I hope that anyone can help me out here.
To force SSL just use the following:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

htaccess redirect primary domain http to https w/out redirect of domains on shared host

I have searched the site and thought I may have found code I could use for my issue, but it did not work.
I want to redirect my primary domain http to https (also including any form of url typed www. without www., http://www, http://, and even just the domain name without www or http before it), while Also not effecting my other domain that is sharing the same hosting within my primary directory (as the SSL I have only used for primary domain, but not used on other domains).
At current, I had code to make the redirect for my primary to https, but it would then make my other domain on same hosting account, also redirect to https.
Then I found code to not effect the other domain and not to redirect to https, but then it effected my primary domain to NOT redirect to https either, it would only redirect to https if with www. or http but would not redirect without the www.
This has been very frustrating because I am VERY new to attempting this type of code, so I don't have a clue what I am doing and could surely use the help. My Godaddy hosting would not help but give link to basic redirect code which does not help for other domains sharing hosting, nor did it work for typing domain without www etc. I hope this made sense.
Thank you in advance.
EDITED possible FIX:
Ok, my code might look a bit wonky and I'm sure it may need cleaning up and possible repetitive stuff removed, but this is what I just patched together from other code offerings I've found on this site, along with others I've found elsewhere and I think it might be working. I'm sure there is a cleaner way to format this, but at current it seems to be working.
# redirect http to https Domain
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} www.yoursite.com [OR,NC]
RewriteCond %{HTTP_HOST} yoursite.com
RewriteRule (.*) https://yoursite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.yoursite\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Rewrite all traffic to https with port

Got a vServer and plesk installed on it (Apache backend, Nginx reverse proxy), plesk is listening on port 8443.
I use the hostname as a domain for easier accesss and SSL certificate domain. So I would like to redirect ALL traffic to specific one:
What I got so far is this rule
return 301 https://www.DOMAIN.com:8443/;
which leads everything to the Plesk Panel URL but if someone is using this
https://DOMAIN.com:8443
he won't be redirected to
https://www.DOMAIN.com:8443
and the SSL certificate won't work (domain based). How can I force every traffic (http and https with the ports 80 and 8443) to
https://www.DOMAIN.com:8443
Thanks in advance
You could HTACCESS to do it:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
What this does is check if the user is trying to access the site without using www and if so redirect to www on the specific port that you wanted.
If you already have your port 80 traffic redirecting to port 8443 and you just want to redirect the rule for www, what I have listed above will work. You can also have mod rewrite redirect based on the port used.
It would look like this:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
You would just need to make sure that each virtual host you are using has the mod rewrite rule in place. You might have to create a virtual host for the extra ports you want to use. The only thing these virtual hosts would have is the redirect rule. Otherwise you might get 404 errors.

mod_rewrite http to https ends up in loop

I've got the problem that I want to redirect my HTTP requests to a HTTPS using a shared SSL certificate. For some stupid reason of my host I have to attach the SSL Port on the request url.
Basically I want to redirect this:
http://sub.domain.com
to
https://sub.domain.com:12345
my .htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}:12345%{REQUEST_URI} [L,R]
By this results in a redirect loop. I have no idea why though. Is this maybe because I use a shared SSL certificate which is not made for the domain and therefore the RewriteCond is always off?
thanks in advance!
EDIT:
I've checked the response header and saw that the location field still points to the non https url. But if I use another domain (or even a subdomain) it works. So why doesn't work the redirect to the same domain?
Try changing your condition to:
RewriteCond %{SERVER_PORT} 12345

redirecting HTTP urls to HTTPS pages

Can someone help me with this?
I manages to redirect already the root access. when someone access my site using sample.com it will redirect in to https://sample.com/ but when someone access the site using this method , sample.com/blog, It still loads the http://sample.com/blog not the https://it should be
The following has worked on most of my projects:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]
The following is inside a .htaccess placed in the root HTML folder of the website. Place additional rewrite rules after this rule.
EDIT: this RewriteCond expects HTTP to run on the standard port 80. Adjust it in case you transfer HTTP over some other port.

Resources