-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubdomainRedirectToParent
32 lines (26 loc) · 1.62 KB
/
SubdomainRedirectToParent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Redirects something.domain.com to domain.com?domain=something.domain.com
#It is useful when you want to allow various clients to have an easy subdomain, but you want to redirect
# them to a single point of entry.
#Oftentimes this scenario comes in to play when you have an SSL certificate on the parent domain only and do not
# wish to purchase a separate SSL cert for each subdomain.
Options -MultiViews +FollowSymlinks
RewriteEngine on
RewriteBase /
#Note that HTTP and HTTPS are in separate sections. A clever person could combine these into one using the SERVER_PORT.
#For simplicity, we have these separated out.
#HTTPS
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} !^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ [NC]
RewriteCond %{HTTP_HOST} !^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} !^portal\.([a-z0-9]+)\.([a-z0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} !^www\.([a-z0-9]+)\.([a-z0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.([a-z0-9]+)\.([a-z0-9]+) [NC]
RewriteRule .* https://%2.%3/login.php?domain=%1.%2.%3 [QSA,R=301,L]
#HTTP
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} !^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ [NC]
RewriteCond %{HTTP_HOST} !^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} !^portal\.([a-z0-9]+)\.([a-z0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} !^www\.([a-z0-9]+)\.([a-z0-9]+)$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.([a-z0-9]+)\.([a-z0-9]+) [NC]
RewriteRule .* http://%2.%3/login.php?domain=%1.%2.%3 [QSA,R=301,L]