You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Spork Schivago <sp...@gmail.com> on 2017/02/20 19:17:31 UTC

[users@httpd] Best way to redirect all traffic to secure website.

Hello,

I was following a post from a user asking about the best way to redirect
all traffic on his server from port 80 to port 443.

Someone linked the original OP to
https://httpd.apache.org/docs/2.4/rewrite/avoid.html#redirect

I decided to post my own question instead of hijacking his question.   For
my website, I've been using RewriteCond and RewriteRules, but I'm
questioning whether is now the best approach or not.

I have some subdomains that get redirected to different ports that run
services that aren't port 443.  For example, when I go to
subdomain1.mydomain.com, it redirects me to mydomain.com:2083.

In this case, could I use a redirect?   Something like:

<VirtualHost *:80>
    ServerName www.mydomain.com
    Redirect "/" "https://www.mydomain.com/"
</VirtualHost>

<VirtualHost *:80>
    ServerName subdomain1.mydomain.com
    Redirect "/" "https://subdomain1.mydomain.com:2083/"
    ...
</VirtualHost>


Then, if I go to something like
http://subdomain1.mydomain.com/test/example.html, would it take me to
https://subdomain1.mydomain.com:2083/test/example.html?

That seems a lot nicer than using all those dang rewrite rules.

Thanks!

Re: [users@httpd] Best way to redirect all traffic to secure website.

Posted by Spork Schivago <sp...@gmail.com>.
Thank you.   I am glad I asked because I must have missed the permanent
part.   I will give it a shot.   I'm on the HSTS preloading list, so most
browsers should redirect to https anyways.   Thanks so much!!!!   It'd be
nice to remove all those rewrite rules from the .htaccess file!   The
article I was originally following talked about the redirect directive in
the Apache config file, but said it would not redirect the $1 or whatever
you want to call it.   For example, they said if I had:
Redirect "/" "https://subdomain1.mydomain.com/"    and someone went to
http://subdomain1.mydomain.com/test/example.html, it'd only redirect them
to https://subdomain1.mydomain.com, and not
https://subdomain1.mydomain.com/test/example.html.

I believe that statement is just incorrect and from what I've been reading,
it will redirect them the stuff after the domain name, which would be
wonderful!

On Mon, Feb 20, 2017 at 4:56 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Mon, Feb 20, 2017 at 8:17 PM, Spork Schivago <sp...@gmail.com>
> wrote:
> >
> > <VirtualHost *:80>
> >     ServerName www.mydomain.com
> >     Redirect "/" "https://www.mydomain.com/"
> > </VirtualHost>
> >
> > <VirtualHost *:80>
> >     ServerName subdomain1.mydomain.com
> >     Redirect "/" "https://subdomain1.mydomain.com:2083/"
> >     ...
> > </VirtualHost>
> >
> >
> > Then, if I go to something like
> > http://subdomain1.mydomain.com/test/example.html, would it take me to
> > https://subdomain1.mydomain.com:2083/test/example.html?
>
> I think so, you probably should try it first, but I don't see why it
> wouldn't work.
> "Redirect permanent / ..." might be interesting too if that's a
> "definitive" redirect, so that browsers use "https:" directly for next
> requests...
>
>
> Regards,
> Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Best way to redirect all traffic to secure website.

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Feb 20, 2017 at 8:17 PM, Spork Schivago <sp...@gmail.com> wrote:
>
> <VirtualHost *:80>
>     ServerName www.mydomain.com
>     Redirect "/" "https://www.mydomain.com/"
> </VirtualHost>
>
> <VirtualHost *:80>
>     ServerName subdomain1.mydomain.com
>     Redirect "/" "https://subdomain1.mydomain.com:2083/"
>     ...
> </VirtualHost>
>
>
> Then, if I go to something like
> http://subdomain1.mydomain.com/test/example.html, would it take me to
> https://subdomain1.mydomain.com:2083/test/example.html?

I think so, you probably should try it first, but I don't see why it
wouldn't work.
"Redirect permanent / ..." might be interesting too if that's a
"definitive" redirect, so that browsers use "https:" directly for next
requests...


Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org