Get blog.domain.com to appear as www.domain.com/blog - mod-rewrite

I want to create a blog for an e-commerce website, but due to data security reasons I don't want to host the blog on the same machine as the website is hosted on. Is there a way to
host it on a separate machine using the sub-domain of blog.domain.com but have it be accessible via the url www.domain.com/blog.
My reasoning is that the content will help with seo better if it uses the same domain.
I was thinking about using mod_rewrite but I'm not sure if it would allow page retrieval from a different website.

It is possible to use the Apache module mod_proxy to make the contents of a server appear to be hosted on another server, and therefore appear to be hosted under a different domain. You might like to take a read of this page which details the Apache configuration directives needed to get it up and running. If that doesn't offer enough options for setting it up how you want it, then you could investigate the "force proxy" option in mod_rewrite, which allows you to send certain rewritten requests through mod_proxy to do the proxying.

Related

Unable to set up custom domain on Heroku using Google Domains DNS?

To preface this, I am new to backend web development so I'm coming at this totally clueless. My past experience is with Netlify, which makes it pretty seamless to add a custom domain to a website with their free DNS service.
To start, I am working on a Flask application that ideally I would like to put on a subdomain of my website (i.e. app.my-website.whatever, not actually my real domain since it includes my real name) on a different host, in this case Heroku, while keeping my main website (www.my-website.whatever) on Netlify. This required me to switch from using Netlify's DNS to using the DNS tools provided by Google Domains.
After deploying the app on the free domain, which went just fine, I tried setting up my domain for the website, following these steps:
On my website's dashboard, I went to Settings > Domains > Add domain and under domain entered app.my-website.whatever, including the subdomain of course.
Copied the DNS Target Heroku gave me.
At my dashboard for my-website.whatever at domains.google.com, under DNS > Default name servers > Resource records, I added a custom record with the hostname app.my-website.whatever (Google Domains automatically adds the .my-website.whatever), type CNAME, TTL 600, and in the Data field I pasted the DNS Target.
In my Ubuntu (WSL) terminal, when I type host app.my-website.whatever, the output says app.my-website.whatever is an alias for {bunch-of-random-characters}.herokudns.com.
Unfortunately, this has not been successful. When I try to visit the domain, I usually get an error such as DNS_PROBE_FINISHED_NXDOMAIN or alternatively ERR_SSL_UNRECOGNIZED_NAME_ALERT. I've also tried the same thing with just www.my-website.whatever, and the same issues occur.
When I try to visit the site, most browsers will automatically append https://, which I would assume doesn't quite work since I do not have a cert set-up for my site, which I need to do manually.
Does the above error mean that there is a problem related to SSL, or is it something else? Is it because my browser forces https:// that I cannot see anything changing (i.e. would http:// work?)?
From what I can tell, I should be able to do all of this on the free-tire, but I have some confusion about a few details, and feel like I could be missing some other things:
Do I need a certificate/SSL for my custom domain to work at all with Heroku?
If it could possibly be an easier solution: Is there a better alternative to Heroku in my case?
With regards to setting up the cert, I tried following the tutorial here:
https://medium.com/#bantic/free-tls-with-letsencrypt-and-heroku-in-5-minutes-807361cca5d3
For certbot, as the tutorial explains, you are given two strings like so: <long-string>.<other-long-string>, and you need to serve a file at /.well-known/acme-challenge/ with the name <long-string> (no extension), but as an unrelated issue, I cannot get Flask to serve this file, even on a local dev server, and I just get a 404 message, which the certbot utility also reports. I can create another file, such as a simple .txt file, in that same directory, and it will serve just fine.
I'll admit, these issues feel a bit basic, but I genuinely am lost, and none of the guides or posts I see online seem to have any remedy or explanation for what is happening here.
If there is any more information I should share, please let me know.

How to setup laravel to use one app and point multiple domains to it

I have multiple domains, and would like to point them all to the same app. I want them all to serve the same pages, but the way it's setup now, I get a 404 not found if I try to go anywhere in the app other than the home page.
I have the nginx server block setup with server maindomain.com www.maindomain.com seconddomain.com www.seconddomain.com thirddomain.com www.thirddomain.com
I also have SSL certificates setup for all the domains listed, and the test out with an A from SSL labs. Question is, how do I get them all to serve the pages in the app, and not just the main domain's homepage?
I have looked at similar questions, but they don't seem to address this exact issue. I don't want multiple domains pointing to different views (that's cool, but not what I need), and I already have a different app with a different name hosted on the same server and working correctly. I've tried forwarding in the past, but it didn't work out (SSL issues).

Hide IP address in source with Website Masking?

I am a bit of a novice on web hosting - We have built a site in Flex that is delivered on a SaaS basis. We have put a dedicated system for a client on a URL of their choosing (purchased through Go-Daddy) and have put a simple forward with Masking on the site. This works fine but in the view source on the browser, it shows the IP address which is obviously a security issue. I have tried changing the IP in the DNS to the IP the site is located at on our server but as we use a sub-IP (i.e. 10.10.100.100:1000), it won't accept it.
Any ideas?
Looks like you want to install a reverse proxy. My understanding of your case is that there's a browser A using your clients site B which either pulls in resources or accesses in some other way from server C. Ypu want to hide all references to server C, so that it looks like B is stand-alone. configure your web server on B to act as a reverse proxy to C for a specific set of resources.

Ensuring folder name doesn't show up in the domain name

our hosting account is set up with the domain www.nashman.ca, and our application is at www.nashman.ca/hub. We have another domain that forwards to www.nashman.ca/hub and that's hub.mhn.co. The problem i'm having with this is that the forwarded domain adds on the /hub whenever you navigate to another page from hub.mhn.co, so the domain shows as hub.mhn.co/hub/admin when you're in the admin area, for example. I need the domain to stay consistent, and never show that folder name, because its breaking some of the javascript I use. What is the best way to set this up?
edit
I've been doing some reading about URL Rewriting, and looking into it - my hosting provider supports the IIS7 URL Rewrite module. All the tutorials I've found so far detail how to set up rules using the IIS config tools, but I don't have access to them. Is there a way to do it by editing my web.config in my apps root directory? And will this solve my issue?
Is the default page for hub.mhn.co using a redirect to www.nashman.ca? If so, what is happening is that the forwarding software basically returns a new URI that the browser requests, and the new URI will replace the old one in the browser window and thus in all future requests. You're probably redirecting to ~/hub/ (the hub subdirectory of the site root) which will result in the browser requesting a new URI that keeps the domain name but tacks on the subdirectory.
If you have direct control over the DNS and your webservers, you can use the DNS configuration to direct a request for the hub.mhn.co domain directly to the /hub subdirectory of your webserver. That way, the browser never knows that hub.mhn.co is actually www.nashman.ca/hub/. You might have to direct to an alternate port on the webserver and map that port to the subdirectory, depending on your DNS software (IIRC, most can deal with ipaddress/subdir routes, but some can only handle routing to ipaddress:port).
If your IT department does not have direct control/ownership over your DNS routing, or your exact hosting environment, you are more or less at the mercy of your hosting provider. They may be able to set up their environment to do the same thing, or not; all you can do is ask.
EDIT: Basically you have two options left if you're hosting remotely and can't use their DNS to reroute silently.
First option: clone (copy all files from) the web layer of nashman.ca/hub as hub.mhn.co under a different root space in your hosting environment (try to keep any hooks to service-layer code over at nashman so you don't have to copy the whole vertical slice). If you must also keep the UI under the /hub/ subdirectory, you're repeating code, but you may be able to mitigate this with deploy scripts that will allow you to deploy one local copy of your codebase to various locations. This may also cost more as your hosting environment is now hosting two non-trivial sites.
Second option: host the site and/or resolve the calls on your own hardware. As long as you have a public, static IP address through your ISP, you can provide a DNS server that will be the "authoritative" server for nashman.ca and hub.mhn.co domains. Your ISP or a third party domain name registry can provide a "pass-down" route to get requests from the TLD servers down to you. Then, you can route requests to whatever IP address, port and/or subfolder you like; that can be a remote webhosting provider (as long as they don't mind JUST hosting your site) or your own webservers. This will require the hardware, and a static IP from your ISP. If you lose power to this server, your site will be unreachable until power's restored. If the IP address of your DNS server changes, your site will be unaccessible by DNS until the server that routes requests to you updates its routing table with the new IP (which can be up to 24 hours).

How to get personalized sub-domains for users and make them work?

Say I have a site hosted on example.com, now I want each of my registered user to get a personalized sub-domain, e.g Alice should normally gets alice.example.com as her sub-domain. While actually alice.example.com gets data from example.com/user/alice. How to implement this mechanism? I see lots of sites are working in this way. I wonder how they did it. Is it some kind of domain server configuration, web-server configuration, .htaccess rewrite or simply some tricks in the code?
If its redirecting, as I experimented, example.com and alice.example.com will get DIFFERENT IP addresses, if that, how rewrite works since when I request alice.example.com, the web browser takes me to a completely different site (IP address).
This has confused me for some time, I just can't figure it out myself, any help would be really appreciated.
[edit]: OK WAIT! I'm afraid I made a duplicate. Check this thread: Create subdomains on the fly with .htaccess (PHP)
Basically you need two parts:
1) Your Nameserver needs to support wildcards. So you would map *.mydomain.com to a single server. This will cause alice.mydomain.com and bob.mydomain.com to all go to the same server.
2) Then your server software should be able to map the hostname (=alice.mydomain.com) to your application and pass in the "alice" part as a parameter.
Depending in what framework/server software you use this should be quite easy.
HTH
Alex
Is it some kind of domain server configuration, web-server configuration, .htaccess rewrite or simply some tricks in the code?
It's probably a combination of the several techniques.
First layer would probably be a Wildcard DNS record on a DNS level so that any sub-domain can be used.
Next, server configuration or application logic is used to separate the content based on the accessed sub-domain. This can be Apache Alias directive or a Rewrite rule or logic in your application code.
I can tell how I did this on pastebin.com
wildcard DNS makes *.pastebin.com go to a single IP
By default, if Apache can't find a matching vhost for a given domain, the first defined vhost picks it up (there are other ways of achieving this, this is just what I did).
So I ensure the pastebin site is the first vhost, and so then software then sees the requested hostname and acts on it accordingly to configure itself

Resources