HTACCESS with HTTPS and subdomain with port
I have spent few hours to find a answers for a simple question, but I didn't. With htaccess on apache server, I want:
1-All traffic to be HTTPS
http://example.com
>> https://example.com
(edit) AND ALSO
2-All traffic to a subdomain to be redirected to a specific port
subdom.example.com
>> subdom.example.com:1234
I have created this piece of crap, but doesn't work in all the cases
RewriteEngine On
RewriteCond %{SERVER_NAME} ^subdom.example.com$
RewriteCond %{SERVER_PORT} !^1234$
RewriteRule ^(.*)$ https://%{SERVER_NAME}:1234%{REQUEST_URI} [L,R=301]
# If not https, then force it
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Finally, nice to have would be to always redirect example.com to www.example.com
Thank you all for your support
.htaccess
|
show 3 more comments
I have spent few hours to find a answers for a simple question, but I didn't. With htaccess on apache server, I want:
1-All traffic to be HTTPS
http://example.com
>> https://example.com
(edit) AND ALSO
2-All traffic to a subdomain to be redirected to a specific port
subdom.example.com
>> subdom.example.com:1234
I have created this piece of crap, but doesn't work in all the cases
RewriteEngine On
RewriteCond %{SERVER_NAME} ^subdom.example.com$
RewriteCond %{SERVER_PORT} !^1234$
RewriteRule ^(.*)$ https://%{SERVER_NAME}:1234%{REQUEST_URI} [L,R=301]
# If not https, then force it
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Finally, nice to have would be to always redirect example.com to www.example.com
Thank you all for your support
.htaccess
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Yes your rules look fine as as I commented earlier should redirect fromhttp://subdom.example.com/
tohttps://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50
|
show 3 more comments
I have spent few hours to find a answers for a simple question, but I didn't. With htaccess on apache server, I want:
1-All traffic to be HTTPS
http://example.com
>> https://example.com
(edit) AND ALSO
2-All traffic to a subdomain to be redirected to a specific port
subdom.example.com
>> subdom.example.com:1234
I have created this piece of crap, but doesn't work in all the cases
RewriteEngine On
RewriteCond %{SERVER_NAME} ^subdom.example.com$
RewriteCond %{SERVER_PORT} !^1234$
RewriteRule ^(.*)$ https://%{SERVER_NAME}:1234%{REQUEST_URI} [L,R=301]
# If not https, then force it
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Finally, nice to have would be to always redirect example.com to www.example.com
Thank you all for your support
.htaccess
I have spent few hours to find a answers for a simple question, but I didn't. With htaccess on apache server, I want:
1-All traffic to be HTTPS
http://example.com
>> https://example.com
(edit) AND ALSO
2-All traffic to a subdomain to be redirected to a specific port
subdom.example.com
>> subdom.example.com:1234
I have created this piece of crap, but doesn't work in all the cases
RewriteEngine On
RewriteCond %{SERVER_NAME} ^subdom.example.com$
RewriteCond %{SERVER_PORT} !^1234$
RewriteRule ^(.*)$ https://%{SERVER_NAME}:1234%{REQUEST_URI} [L,R=301]
# If not https, then force it
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Finally, nice to have would be to always redirect example.com to www.example.com
Thank you all for your support
.htaccess
.htaccess
edited Nov 29 '18 at 9:41
Alex
asked Nov 27 '18 at 19:42
AlexAlex
23114
23114
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Yes your rules look fine as as I commented earlier should redirect fromhttp://subdom.example.com/
tohttps://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50
|
show 3 more comments
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Yes your rules look fine as as I commented earlier should redirect fromhttp://subdom.example.com/
tohttps://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Yes your rules look fine as as I commented earlier should redirect from
http://subdom.example.com/
to https://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50
Yes your rules look fine as as I commented earlier should redirect from
http://subdom.example.com/
to https://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506982%2fhtaccess-with-https-and-subdomain-with-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506982%2fhtaccess-with-https-and-subdomain-with-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
https ://subdom. example.com is not redirecting to https ://subdom. example.com:1234 Sorry for the space, but don't know how to avoid the auto-link
– Alex
Nov 27 '18 at 22:32
thanks @anubhava, I have not been able to understand the htaccess background. I see this as a runable script that runes from top to bottom... But not sure. Anyway, even when the first rule should already redirect, I guess there is something wrong somewhere because it does not redirect as expected.
– Alex
Nov 28 '18 at 8:31
Can you show ViftualHost config of your subdomain in question
– anubhava
Nov 28 '18 at 8:34
Well, all this is behind a synology nas, so I am not used to the console, nor the file structure, so don't have an idea how to get the info you ask for. If you believe the htaccess syntax is correct and the issue could be in the VirtualHost please confirm and I will spend all needed time to find the config of VirtualHost in my nas
– Alex
Nov 28 '18 at 13:22
Yes your rules look fine as as I commented earlier should redirect from
http://subdom.example.com/
tohttps://subdom.example.com:1234/
– anubhava
Nov 28 '18 at 14:50