- Apache Server Configuration via .htaccess
- 01 Mar 2017 01:34:16 pm Permalink
- Last edited by Nik on 22 Apr 2017 01:48:46 pm; edited 1 time in total
So, while most minor problems can be solved with a quick Google query, I think I am stuck with this one:
1) I need to rewrite all subdomains to the second level domain
2) I need to force all traffic to go via HTTPS
Example: http://abc.example.com/12345/ -> https://example.com/12345/
I did this:
Code:
And it seems to work fine, except if I input something like "https://abc.example.com" which somehow totally screws up. (EDIT: Let me elaborate: Using HTTPS and a subdomain makes it rewrite to HTTP and keep the subdomain.)
So, yeah, my knowledge in cryptography is not enough yet to decipher what these configs do, and Google can't help me either. Could someone slap something quick together here?
1) I need to rewrite all subdomains to the second level domain
2) I need to force all traffic to go via HTTPS
Example: http://abc.example.com/12345/ -> https://example.com/12345/
I did this:
Code:
RewriteEngine On
RewriteCond %{http_host} ^(.+)\.example.com [nc]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
And it seems to work fine, except if I input something like "https://abc.example.com" which somehow totally screws up. (EDIT: Let me elaborate: Using HTTPS and a subdomain makes it rewrite to HTTP and keep the subdomain.)
So, yeah, my knowledge in cryptography is not enough yet to decipher what these configs do, and Google can't help me either. Could someone slap something quick together here?