1
votes

On a Django 1.9 project I need to redirect:

https://example.com/app/

to

https://examplebucket.s3.amazonaws.com/app/index.html

But I need https://examplce.com/app/ to be still visible on the browser address bar...

I know this must be possible in theory with Django because the previous team working on this project did a setup to serve the /static/ media files from an S3 bucket. And if I access those static files via https://example.com/static/app/index.html, they are served from the S3 bucket but the browser address bar still shows the original url I input.

I'm deploying an Ionic Browser project and I want the files (including the index) to be served from the S3 but the url needs to be user friendly, thats the reason.

1
That's not possible, the browser always shows the location of the file that is served. Also for static files, you don't want to redirect, but just point to the AWS location in your HTML sources (<img src="https://blabla.s3.amazonaws.com/...">). What you can do, is setup a CDN (for example CloudFront) to use a subdomain (e.g. static.example.com) that belongs to you. Then you point to that (<img src="https://static.example.com/...">) instead.dirkgroten
Note that it's not clear from your question what is a static file. Is index.html itself a static file or a web page served from your django server that contains static files? If so, look at the source of index.html, what's the url for the images contained in index.html?dirkgroten
@dirkgroten index.html is an html file that references to the static files (js, mostly) but I need index.html file and the js files to be in the same domain because else all kind of CORS issues turn upCruclax
As I said, that's not possible if you host your static files on AWS (or any server that's not your server). But CORS shouldn't be an issue, you can enable CORS in your S3 buckets so that your website can access your s3 resources. The same is true for your CloudFront distribution, where in addition you can configure your own subdomain so it 'looks' nicer for users that look into the source or open one of your images in a separate tab. But you'll still need to configure AWS to send the correct CORS headers anyway.dirkgroten

1 Answers

2
votes

The old (dirty) way of doing this is frame-based forwarding.

You set up an iframe on a page in /app/ which points at the real app, letting the url stay the same.

It's not considered a good practice because of security issues (can't be sure where you are typing credentials into), and bookmarking issues (url is always the same so can't bookmark inner pages).

Another alternative is to set up a proxy script that just takes the url, turns that into the equivalent aws url, downloads it and then returns it. This would break the benefits of your cloud hosting if it has multiple regions... it would always be passed through the bottleneck of your server.