SSL infinite redirect - .htaccess

so we recently added an SSL cert to one of our addon domains, but it caused every domain on the server to forward to it. I was able to get it to stop by adding the following to my .htaccess file, but now I get an infinite redirect loop and I have no idea how to fix it.
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} !^implantwideseminars\.com
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
Any help at all would be appreciated

RewriteCond %{HTTP:X-Forwarded-SSL} !on
here you're saying that if it's NOT on SSL, it should redirect to http://%{HTTP_HOST}/$1
notice the missing s on http ?
Try with:
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} !^implantwideseminars\.com
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]

Related

How to map different URL with .htaccess

I need all my domains to have the https certificate, but when I created the .htaccess file, the website wen't down.
Here's the story:
I have a Ruby on Rails website let's call: web1.com.br
I also have the domains: web1.com, web2.com.br and web2.com
I made the DNS mapping so whenever people type those 3 domains, they all go to my original host on web1.com.br (and not changing the url for the user) and it works fine.
But I don't have my https certificate when someone types the other 3 domains. Only on my original website web1.com.br I have the let's encrypt certificate
I asked my host provider for help and they told me to add to my www folder a .htaccess file but I probably did something wrong.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web1\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com\.br$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com\.br$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
I created the .htaccess file and my website (on all domains) went off, giving a 500 response:
"The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at web#web1.com.br to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."
I deleted the file and the site went back online
As you can probably tell, I'm a total noob but can't find someone to help me. I don't know if I did the .htaccess wrong or my hosting support gave me the wrong information.
Thank you
Check this rules in your .htaccess file, redirect all to https://web1.com.br/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?web1\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]

https redirect with htaccess file

I wanted all my domains (http-www, http-non-www and also https-non-www) be redirected to HTTPS-WWW-example-com
My .htaccess code seems to be working, but I really don't know how to check it. I am very doubtful if it works OK because google WMT indexes a lot of pages separately and that's for sure that something is wrong. I really want to avoid too much redirects which it seems to be the case
Here is my code:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Please guys if this code happens not to be good and you send me another one please write whole domain in it because I'm beginner and might screw something up. I appreciate your time.
RewriteEngine On
RewriteCond % { SERVER_PORT } 80
RewriteRule ^ (. * )$ https://yourdomain.com/$1 [R=301,L]
This should work for yah!
Try this code :
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
I would suggest instead relying on .htaccess, you should change domain's vhost config and redirect domains accordingly.

Configuring folder to use SSL

I have a domain: http://example.xoc.uam.mx. I want to require the use of SSL in it (it's a folder of a server). I have this code in the .htaccess but it's not working. What I am doing wrong?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^example\.xoc\.uam\.mx$ [NC]
RewriteRule ^(.*)$ https://example.xoc.uam.mx$1 [R,L]
PS. I already have all the SSL features working, this is, I think, the only thing I miss.
Best Regards.
Your code has some errors. To parse domain name you must use HTTP_HOST instead of REQUEST_URI.
You can replace it by this one
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.xoc\.uam\.mx$ [NC,OR]
RewriteCond %{HTTP_HOST} ^111\.222\.333\.444$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

Can't get my htaccess to work on a 301 redirect

I’m trying to redirect an https://www.domain.ext to a plain https://domain.ext, but just can’t get it to work; this is where I’m right now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^https\:\/\/www\.cadenanoticias\.mx$
RewriteRule ^/?$ "https\:\/\/cadenanoticias\.mx" [R=301,L]
Allso tried
RewriteEngine on
RewriteCond %{HTTP_HOST} *!^https\://www*.cadenanoticias\.mx [NC]
RewriteRule (.*) https://cadenanoticias.mx/$1 [L,R=301]
And not working see: https:www.cadenanoticias.mx
Any idea on why it’s not working?
UPDATE FIX
Got it to work as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.cadenanoticias\.mx$ [NC]
RewriteRule ^(.*)$ https://cadenanoticias.mx/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.cadenanoticias\.mx$ [NC]
RewriteRule .? https://%1%{REQUEST_URI} [R=301,L]
Hope it helps someone else.
%{HTTP_HOST} does not match against protocol. Use
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.cadenanoticias\.mx$ [NC]
RewriteRule ^(.*)$ https://cadenanoticias.mx/$1 [R=301,L]
EDIT :
No, bypassing the SSL certificate validation is not possible. The SSL handshake precedes htaccess rules for security reasons. If this was possible, a hacker could hijack a SSL connection to an insecure one without really needing a valid certificate.
There's no solution for this other than buying a cheaper certificate just to do handshake and redirect.

Redirecting from https to http with the exception of some URI's

So the problem I am currently having is that our entire website is indexed using https. we want to redirect to http using .htaccess. the problem is that we need a couple of URIs to still use https and I am not sure how to write the exception for URIs
I know the below example would work if our site functioned like this www.example.com/account.php but our site urls are like www.example.com/index.php?l=account
# Turn SSL on for account
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
how can i fix this, any guidance would be appreciated.
thanks
EDIT!
So this code below I have working but I would like to make one more exception that I cant seem to get to work, I also want the root (index.php) to only use http.
I tried using...
RewriteCond %{REQUEST_URI} !^/index.php
but this did not work
# invoke rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{https} off
RewriteCond %{QUERY_STRING} !^l=product_detail
RewriteCond %{QUERY_STRING} !^l=product_list
RewriteCond %{QUERY_STRING} !^l=page_view
RewriteRule ^(.*)$ https://%{HTTP_HOST}/development/$1 [R=301,L]
thanks
Try
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/account.php
RewriteCond %{QUERY_STRING} !^l=account
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/account.php [OR]
RewriteCond %{QUERY_STRING} ^l=account
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Resources