Enforce https without www for subdomain - .htaccess

I have phpbb forum which I would like to be viewed only over SSL.
For an example it will be like
If www.subdomain.domain.com - https://subdomain.domain.com
Or
If subdomain.domain.com - https://subdomain.domain.com
I tried several answers which I could find non of them are working properly. Some returning 500 internal server error some aren't enforcing only SSL.
Can anyone suggest me something which I could use in htaccess?

Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?sub.domain.com
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://subdomain.com/$1 [L,R]

Related

Forwarding a subdomain to another subdomain [duplicate]

Does anyone know a way to do a permanent redirect from a.example.com to b.example.com? I have other subdomains that need to remain as they are though. so:
first.example.com -> second.example.com
third.example.com is fine
fourth.example.com is fine
I want to do this in the <VirtualHost> block rather than an .htaccess to avoid having to redeploy again.
Any thoughts would be appreciated, thanks
Add the following RewriteRule to your VirtualHost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule ^ http://second.example.com [R=301,L]
If you wanted to redirect first.example.com/some/url to second.example.com/some/url:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule /(.*) http://second.example.com/$1 [R=301,L]
Recommend you use [R=302] whilst testing the rules to avoid problems with 301s getting cached by your browser.

Symfony2 redirect from http to https

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.

Redirect & SEO (SSL Redirect)

So I bought an SSL for my website, and to redirect the HTTP to HTTPS, I use the following
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
It works great. No problem. But the issue is when I do some basic Speed Tests & SEO test, theres always an error saying things similar to "disable redirect for better speed, seo".
But If i delete .htaccess redirect, there would be issues with HTTP/HTTPS
How can i solve this problem? Is there any other way to make the SSL work without redirecting?
Just In Case Information; I use Godaddy Linux Server.
Thanks in advance.
use this code in your .htaccess file to solve SSL problem
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
if RewriteEngine already "On" then no need to "On" again. I hope this will work perfectly.

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]

redirect SSL subdomain to non SSL subdomain

I'm completely lost as I've tried a variety of ways to get this accomplished, but nothing seems to work.
All I want to do is get the following setup:
FROM: https://sites.example.com
TO: http://sites.example.com
NOTE: same "sites" subdomain, except I do not want the subdomain "sites" to have https://
I also do want to keep my SSL for all other areas except the "sites" subdomain.
Thanks in advance,
JR
You can use:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^sites\. [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

Resources