Mobile app version of vmapp.org
Login or Join
Bryan171

: Most seamless way to direct around port 80 and autoredirect to https with Apache I'm working with a home server and my ISP blocks port 80. I have DD-WRT set up on my router so that I can

@Bryan171

Posted in: #Apache #Isp #PortForwarding #Redirects #UrlRewriting

I'm working with a home server and my ISP blocks port 80. I have DD-WRT set up on my router so that I can redirect other open ports (like 443 and 8080) to the server. I also have dynamic DNS set up on an automatically updating A record via NameCheap.

My end goal is this: a user goes to http:/dev.homeserver.com and automatically gets dev.homeserver.com with no custom ports in the address bar. I want to autoredirect to https because I feel encryption is important and https should be everywhere. Furthermore, I'd like to be able to redirect http:/homeserver.com to homeserver.com and all requests such as http:/homserver.com/blah/this/index.php? to be auto redirected to homserver.com/blah/this/index.php?, etc.

The problem is that in order for me to send users to the server via our domain (say, dev.homeserver.com), I need to redirect them to a port other than 80 to get to the server. Right now I'm doing this via a name cheap URL redirect that takes host dev and redirects it to http:/dev.homeserver.com:8080. This works, but the problem is the port shows up in the URL, which I'd like to avoid. I can enable URL masking, but then the address bar always says dev.homeserver.com and that can be annoying since myself and my colleagues are usually copying out of the addy bar when testing PHP and coding.

I see no-ip has a way of doing this with what they call a Port 80 Redirect: but it just looks like it forwards to an IP and loses the dns name in the address bar as soon as the site responds.

I also have a VPS with port 80 open and have read a bit on ProxyPass but I want to avoid creating dependencies between the home server and VPS. Still, I'd like to hear if this could be an option if it's the only way forward.

(had to get rid of one / in links since it won't let me post urls with my current reputation)

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Bryan171

2 Comments

Sorted by latest first Latest Oldest Best

 

@Bryan171

Actually this was definitely possible (and totally free) with a lot of hacking, and trial and error. I did stand up a reverse proxy on a VPS, which worked well, but I still didn't like the dependency it created on the VPS having to be up (since the two servers I have are totally doing unrelated things).

I initially tried CloudFlare and its advanced url rewriting engine, and it was able to rewrite url requests from 80 ()http) to 443 (HTTPS). The problem is that it tries to communicate with the A record on port 80 (see www.lowendtalk.com/discussion/50106/cloudflare-proxy-origin-other-than-port-80). Also, the free version of CloudFlare only grants you five total advanced dns options. I have about 8 subdomains, so this wouldn't work either.

I happened to be fiddling with my Namecheap domain and realized the DNS settings offer a URL rewrite, so I tried redirecting sub.example.com to sub.example.com. I didn't get an error message instantly, which happened with dynu.com and afraid.com. Those won't let you save this config. In fact, afraid tells you that it is not possible because it would create an "infinite loop", which is true to some extent because the A record (or CNAME record) is technically ambigious to the url to be rewritten.

Something with Namecheap (the special A+ dynamic record, maybe?) allows you to do this kind of redirect. I couldn't find anything in their docs that mentions this. The interesting thing is that a traceroute to your dns record gets you nowhere, and if you ping your dns name, it doesn't give you your server ip, but instead a Namecheap server ip, so I think it must be some sort of reverse proxy setup on their end. Keep this in mind if you're going to do something like WoL (you'll need a separate A record). So far I haven't ran into any issues.

Anyway, Namecheap offers free DNS management services, so I grabbed that and set up DNS-O-MATIC and had a perfectly working site hosted at home. Now anytime a visitor attempts to go to http:/sub.example.com/xyz they're always redirected to https:/sub.example.com/xyz totally seamlessly and without any port garbage in the url. The ports seem minor but if I give someone a link verbally, it's a lot easier.

Hoping this saves someone else from spending as much time as I did on it.

UPDATE:

The namecheap solution no longer works. I believe they applied a patch or altered the rewrite rules within the last six months which no longer allow for this configuration due to A record/URL rewrite conflicts like other DNS providers. I've abandoned hope--at this time there's no free solution out there without implementing a reverse proxy, or until CloudFlare allows you to specify a port other than 80.

If anyone knows an advanced DNS provider that can do what namecheap used to do, please let me know.

For anyone interested, there's an interesting article on how to create a reverse proxy for free using an Azure Web Apps free trial but it appears there's a 165 MB quota per day. Still though for most people this would work. The link to this article is in my below comment since I don't have enough reputation to post.

10% popularity Vote Up Vote Down


 

@Karen161

If you use Cloudflare, their Page Rules will allow you to set up redirects like this. Make sure to set SSL to "Full" under the Crypto tab so it connects to your server over HTTPS as well.



You'll need to use their DNS, but it makes handling this sort of thing a lot easier. Plus it alleviates stress on your home server.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme