Rewrite unsecured subdomain to secured - .htaccess

I know this has been answered, as in this post htaccess redirect HTTPS to secure.domain.com, non https to www.domain.com
but I just can't get this to work. I have two ip addresses. One points at the main domain, domain.com that is not secured. The second points at the subdomain.domain.com which is secured. What I need is for subdomain.domain.com to be rewritten to https://subdomain.domain.com. If anyone has any more information that could help with this I would be so very thankful. This is the .htaccess code I am currently using with no success-
#Non-secure requests to subdomain.domain.com should redirect to https://secure.domain.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Did you turn on RewriteEngine?
Options +FollowSymLinks
RewriteEngine On
make sure these two lines are above the line in your post.

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]

How can I redirect HTTPS to HTTP in .htaccess for specific domains?

We host a number of websites on our server. Our main site, let's call www.domain.com.
Anyway, we noticed that the other sites we host, etc, all point back to our main site (domain.com) when https:// is put in front of their domain. Part of the problem is that these are indexing in Google as well.
I've wondering how I can redirect all these in the htaccess - please help!
Add these rules to the htaccess file in your www.domain.com document root, preferably above any other routing rules that may be there:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R]

htaccess redirect where subdomain

I have a site example.com. Any traffic to www.example.com is redirected to example.com in the .htaccess file using:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
This piece of code that I swiped of the interweb works fine.
I have now added a subdomain subdom.example.com. Similar, any traffic to www.subdom.example.com should be redirected to the non www canonical version.
The following code does not work:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://subdom.example.com/$1 [R=301,L]
Presumably redirects work a little differently where subdomains are involved. Could anyone share how I would edit the above snippet to redirect any www. traffic to the canonical non www. subdomain version?
I believe you don't have sufficient RewriteCond conditions for both redirects. What is happening is that first one is unconditional redirect and since it appears first it always fires and 2nd one never fires.
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Above code will work with both of your domains.

How to redirect non-www to www with SSL for a specific domain not all parked domains

I have test.yoursite.com parked on example.com and have a SSL multi-domain certificate.
What I am asking is:
when http://example.com requested, .htaccess should redirect it to https://www.example.com;
when http://test.yoursite.com requested htaccess should redirect it to https://test.yoursite.com.
One of directions should work both with www and SSL redirection, another one is just for SSL redirection.
By the way I also have example.net parked on same host. I have tried several things which did not work. Waiting for your help.
Try
# Dealing with a domain with/without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://www.%2.%3/$1 [L,R]
# Dealing with a domain that doesn't care about www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://%1.%2.%3/$1 [L,R]
The first rule will redirect http://www.example.com/something to https://www.example.com/something as well as http://example.net/foo to https://www.example.net/foo
The second rule will redirect hosts that don't care about the "www", such as http://subdomain.domain.com/bar to https://subdomain.domain.com/bar
It will not, however, redirect http://sub-sub.subdomain.domain.com/.

301 Redirect where 2 domains point to same IP?

I have 2 TLDs example.com and example.ie.
example.com and example.ie both point at the same IP address and pull the same content now we could get whacked with a ban hammer from Google for duplicate content so we want anyone accessing *.example.ie and *.example.com to be redirected to www.example.com the problem is as they are both pointing at the same server the .htaccess is the same thus I don't believe we can do the usual:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So how do we go about creating a search-engine friendly 301 redirect from *.example.ie and *.example.com to www.example.com?
I would do it like this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
That will redirect (statuscode 301 "permantly moved") every domain which is not www.example.com to www.example.com.
The 301 redirect you posted is just fine; the HTTP header of every request (nowadays) contains the name of the host.
As an alternative, you can use rel=canonical. It's not that urgent anyway, as duplicate content on just two domains is unlikely to be a problem.

Resources