16

I have a site (Made in iWeb) that I am hosting on Amazon S3. I am trying to get www.domain.com/Apps/Physics.html to turn into www.domain.com/Apps/Physics.

I am trying to accomplish this with an .htaccess file. The file is stored in the root of the bucket (where the index.html file is). Here's the problem: It doesn't work. Still can't use www.domain.com/Apps/Physics.

I have a GoDaddy domain, hosted on the S3 server. Does this help?

Undo
  • 25,519
  • 37
  • 106
  • 129
  • 1
    Somehow I doubt Amazon S3 uses Apache to serve your files (.htaccess isn't part of any standard - it's an Apache-specific feature) – Matti Virkkunen Dec 30 '12 at 23:38
  • @MattiVirkkunen I was thinking the same thing... There still has to be a way to do it, though... – Undo Dec 30 '12 at 23:40
  • The service does describe itself a "simple storage service" so I wouldn't be surprised if they didn't have features that are commonly used for running websites instead of plain data storage. – Matti Virkkunen Dec 30 '12 at 23:43

5 Answers5

8

Why don't you add CNAME record 'static' for domain.com (this one for S3) and host www on a Apache server and a rewrite rule like this:

RewriteEngine On

RewriteRule ^somefolder/(.*)$ http://static.domain.com/$1 [P]

OR

#This will save your time of creating the additional CNAME step    
RewriteEngine On

RewriteRule ^somefolder/(.*)$ http://yourbucket.s3.amazonaws.com/$1 [P]

EDIT: Using mod proxy seems to be a better option.

Aniruddh
  • 7,648
  • 1
  • 26
  • 43
  • What would this rule do exactly? How would a request for `static.domain.com` (which this is presumably looking for) end up on the Apache server in the first place? – Matti Virkkunen Dec 30 '12 at 23:55
  • 3
    Proxying everything via your server nullifies some of the benefits of using S3 in the first place. Besides, this person has a static website, setting up a reverse proxy configuration just to serve some files from S3 is overkill. – Matti Virkkunen Dec 31 '12 at 00:34
  • Agreed. I don't see any other way to achieve this. If he desperately wants this: it is the workaround. :) – Aniruddh Dec 31 '12 at 00:36
7

Anno 2016 Amazon S3 supports redirects.

Kristof Van Landschoot
  • 1,427
  • 1
  • 12
  • 30
  • Still doesn't accomplish exactly what I wanted, but it's much closer. – Undo Nov 24 '16 at 15:51
  • 1
    Limit of 50 redirects though which could be an issue – Andre Van Zuydam Oct 15 '19 at 10:31
  • We have used "Redirect requests for an object" https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-page-redirect.html#redirect-requests-object-metadata that help you circumvent the 50 limit. Just an empty file of the same name with the metadata `x-amz-website-redirect-location` set to the desired destination. It's not ultra-flexible, but does work. – campeterson Jan 04 '23 at 21:55
6

S3 is a content server and not a web server. You may want to try renting a small Amazon EC2 instance with Apache to do what you want.

greenimpala
  • 3,777
  • 3
  • 31
  • 39
3

Amazon S3 only serves static content.

To request an user and a password you need to use a "middle" application like s3auth.

You can install in your own server or use their online solution here.

Manube
  • 5,110
  • 3
  • 35
  • 59
jotacor
  • 2,878
  • 1
  • 18
  • 19
1
  1. Set your S3 bucket as a Static Host
  2. Create a CloudFront distribution
  3. Ensure your Origin is the address of the S3 static host and not the S3 bucket *important
  4. Serve you page as index.html in the folder Physics
Anton Swanevelder
  • 1,025
  • 1
  • 14
  • 31