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

39 Views Asked by At

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]
1

There are 1 best solutions below

3
On

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]