httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Schroeder <paul.schroe...@nimbix.net>
Subject [users@httpd] Re: mod_rewrite behavior when port is specified
Date Tue, 07 Mar 2017 04:15:28 GMT
Ah, I see what was going on.  The port being included in the HTTP_HOST var
was causing the initial rewrite to be written as an invalid URL.  It
appears the mod_rewrite was then assuming that this wasn't actually a
redirect and that it needed to prepend the '/' because of this.  I was
distracted by the prepended '/'.  I don't know how I didn't see that
before.  At any rate, here is a solution that works:

RewriteCond %{HTTP_HOST} ^([^:]+):?.*
RewriteRule ^/?(.*) https://%1:443/$1 [R=301,L]

Cheers...Paul..


On Mon, Mar 6, 2017 at 4:18 PM, Paul Schroeder <paul.schroeder@nimbix.net>
wrote:

> Hello..
>
> I'm seeing an issue where mod_rewrite seems to behave differently when the
> client connects to my VirtualHost and includes the port as a part of the
> URL.  i.e.  http://xenial.localdomain vs. http://xenial.localdomain:80
>
> With this RewriteRule, the redirection that I want (to my SSL VirtualHost
> listening on port 443) is working just fine as long as the client uses
> http://xenial.localdomain as the URL:
>
> RewriteRule ^/?(.*) https://%{HTTP_HOST}:443/$1 [R=301,L]
>
> However, when the port is specified ( http://xenial.localdomain:80 ), the
> redirect does not work as expected.  I see the following in my logs:
>
> 192.168.122.1 - - [06/Mar/2017:18:57:58 +0000] "GET / HTTP/1.1" 301 595
> "-" "Links (2.13; Linux 4.8.13-100.fc23.x86_64 x86_64; GNU C 5.3.1; text)"
> 192.168.122.1 - - [06/Mar/2017:18:57:58 +0000] "GET /
> https://xenial.localdomain:80:443/ HTTP/1.1" 301 662 "-" "Links (2.13;
> Linux 4.8.13-100.fc23.x86_64 x86_64; GNU C 5.3.1; text)"
> 192.168.122.1 - - [06/Mar/2017:18:57:58 +0000] "GET /
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/ HTTP/1.1" 301 798
> "-" "Links (2.13; Linux 4.8.13-100.fc23.x86_64 x86_64; GNU C 5.3.1; text)"
> 192.168.122.1 - - [06/Mar/2017:18:57:58 +0000] "GET /
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/ HTTP/1.1" 301 1070 "-" "Links (2.13;
> Linux 4.8.13-100.fc23.x86_64 x86_64; GNU C 5.3.1; text)"
> 192.168.122.1 - - [06/Mar/2017:18:57:58 +0000] "GET /
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/
> https://xenial.localdomain:80:443/https://xenial.
> localdomain:80:443/https://xenial.localdomain:80:443/ HTTP/1.1" 301 1614
> "-" "Links (2.13; Linux 4.8.13-100.fc23.x86_64 x86_64; GNU C 5.3.1; text)"
>
> As you can see, a '/' is being prepended to the rewritten URL and
> recursion occurs which eventually causes the URL to become too long and
> cause an error.  Why does specifying the port in the URL cause mod_rewrite
> to behave differently?  Is there a better way for me to do this?
>
> Normally, this wouldn't be an issue, but I need to be able to run this
> VirtualHost on a port other than 80.
>
> Thanks in advance for any suggestions...Paul..
>
>
> ---
>
> Paul B Schroeder <paul.schroeder "at" nimbix "dot" net>
>



-- 
-- 
---

Paul B Schroeder <paul.schroeder "at" nimbix "dot" net>

Mime
View raw message