Symfony2 redirect from http to https - .htaccess

I know guys this question has been asked many times but believe me I have tried all the solutions in the other questions without any results.
As mentioned in the title I want all my http requests to be converted into https requests, and I want to use .htaccess file to do this so this is what I have tried so far:
#https redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
But this gives me nothing my site is not being redirected from example.com to https://example.com
What am I missing here ?

As worked out in a lengthy communication via chat the issue was that the redirection rules were coded after (below) other internal redirection rules, so never got applied.
Moving the http to https redirection rules up solved the issue.

Related

.htaccess specific code to redirect http traffic to https and redirect subdomain traffic to offsite domain

I have recently set up a site "saskatoonwashworld.com" with SSL. I have two issues that I need to resolve...
1) Route all http requests to https (I was able to do this easy enough with code found online)
2) I also have a subdomain "portal.saskatoonwashworld.com" which I want redirected to "https://secure3.washcard.com/AP?CID=65e53149-59e9-4d67-a746-e475aa4bc7be" which is hosted by another site. I want the requests to go here whether or not the user types in http://portal.###, https://portal.###, or just the url without the http(s).
I cannot figure out how to do it as I don't know how to properly code the conditions and rewrites.
I was originally using this code found online for the http to https redirect...but if I'm understanding it correctly, it is using a wildcard to catch "www." and so would ignore/override my "portal." subdomain anyways. But I could be wrong.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://saskatoonwashworld.com/$1 [R=301,L]
Try this rewrites in .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?portal\.saskatoonwashworld\.com [NC]
RewriteRule (.*) https://secure3.washcard.com/AP?CID=65e53149-59e9-4d67-a746-e475aa4bc7be [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://saskatoonwashworld.com/$1 [L,R=301]

HTTP to HTTPS 301 Redirection Code is Not Working, It says Too many redirects

I am using Bluehost for one of my websites. Recently, Recently, i have moved my site from HTTP to HTTPS .
After that, I have used So may different code including the below code to force HTTPS all over my website.
# SSL Rewrite
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
After using this post, when I check redirection on redirect-checker available on online, I get following messages.
But it is not working. Too many redirects. Please try to reduce your
number of redirects for http://www.example.com. You use 19 Redirects.
Ideally, you should not use more than 3 Redirects in a redirect chain.
More than three redirections will produce unnecessary load on your
server and reduce speed, which ends up in bad user experience.
And If you want to access my website from a browser, I get warning as such:
The www.example.com page isn’t working. www.example.com redirected you
too many times.
I think some redirection loop was creating such problem.
However,
My web site Status Right Now: Without using any code on htaccess
https//www.example.com is working just fine. returning 200 OK. 200 OK2
https//example.com is now 301 redirected to https//www.example.com (So, i think it is also just fine)
The problem is:
http//example.com is now 301 redirected to http//www.example.com
http//www. example.com is returning 200 OK.
To solve problem 3, I included Below code on my htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
After that I found that:
http//example.com is now 301 redirected to https//www.example.com
So the problem is solved for:
http//example.com
https//example.com
https//www.example.com
Now I just need some code to redirect 301 only:
http//www.example.com TO https//www.example.com`
Can anybody help me here?
And I am sorry if I explain my problem in a wired way... :D. The matter is I am not an expert guy on this. Hope you all will understand.
Try this:
RewriteEngine On
# If not www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# rewrite to https and www
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
# If not HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

.htaccess url rewriting issue: http to https with exception for a directory

I am currently using the following .htaccess code to rewrite:
http://force-t.fr to https://www.force-t.fr
http://www.force-t.fr to http://www.force-t.fr
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.force-t.fr$
RewriteRule ^(.*) https://www.force-t.fr/$1 [QSA,L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.force-t.fr/$1 [R=301,L]
Now, I need to add two exceptions :
All url starting with force-t.fr/iot/ needs to be accessible via http or https.
IE8/XP users needs to access the www.force-t.fr website in http only
(SNI is not supported by IE8/XP and my certificat is not working for them.)
I don't know how to do this and spend two hours searching without success.

How to use htaccess to redirect to www and https without having too many redirects error

I'm really stuck, as this is not my area, but I can get the following to work to redirect to www version, but as soon as I add another redirect to https (just bought the ssl and want to use it!) I get the "too many redirects" error.
This is what I have in my working .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^talbotandbourne.co.uk
RewriteRule (.*) http://www.talbotandbourne.co.uk/$1 [R=301,L]
ErrorDocument 404 /404.html
So how do I add a redirect to https as well?
Many thanks for any help received. I've looked all over the site for the answer to this question, and tried many suggestions from other posts, but I still get the error. I think I'm probably punching above my weight!
Redirecting to www:
RewriteCond %{HTTP_HOST} ^talbotandbourne.co.uk
RewriteRule ^ https://www.talbotandbourne.co.uk%{REQUEST_URI} [R=301,L]
and, redirect http to https:
RewriteCond %{HTTPS} Off [NC]
RewriteRule ^ https://www.talbotandbourne.co.uk%{REQUEST_URI} [R=301,L]

force outgoing links as http vs https on secure domain? (htaccess?)

I have forced a ecommerce site to be always in https, due to some issues with having only specific urls triggered as secure. I have used the following in my .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.vshoen.com/$1 [R,L]
But now my problem is all external links without www in the url open in https as well for some reason. Most of the time its not a problem but there are a few specific links that need to simply be http://url.com instead of http://www.url.com and for in this case they are not loading as its trying to open them as https://url.com
I was hoping there would be a resolution to this, this is a wordpress site if that makes any difference.
Thanks in advance.
Try this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

Resources