PUT Bucket website
API Description
You can use this API to set website hosting for a bucket.
Method Definition
ObsClient.setBucketWebsite
Request Parameter
Field |
Type |
Optional or Mandatory |
Description |
||
---|---|---|---|---|---|
Bucket |
String |
Mandatory |
Bucket name |
||
RequestDate |
String or Date |
Optional |
Request time
NOTE:
When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards. |
||
RedirectAllRequestsTo |
Object |
Optional |
Redirection rule of all requests |
||
HostName |
String |
Mandatory |
Host name used for redirection |
||
Protocol |
String |
Optional |
Protocol used for redirection. Possible values are:
|
||
ErrorDocument |
Object |
Optional |
Error page settings |
||
Key |
String |
Optional |
Page that is returned when a 4XX error occurs |
||
IndexDocument |
Object |
Optional |
Default page settings |
||
Suffix |
String |
Mandatory |
Suffix that is appended to a request initiated for a folder. For example, if the suffix is index.html and you request for samplebucket/images/, the returned data will be the object named images/index.html in the samplebucket bucket. The suffix can neither be null nor contain slashes (/). |
||
RoutingRules |
Array |
Optional |
Redirection rule list |
||
Condition |
Object |
Optional |
Matching condition of a redirection rule |
||
HttpErrorCodeReturnedEquals |
String |
Optional |
HTTP error code to be matched when a redirection rule takes effect |
||
KeyPrefixEquals |
String |
Optional |
Object name prefix to be matched when a redirection rule takes effect |
||
Redirect |
Object |
Mandatory |
Details about a redirection request |
||
Protocol |
String |
Optional |
Protocol used for redirection. Possible values are:
|
||
HostName |
String |
Optional |
Host name used for redirection |
||
ReplaceKeyPrefixWith |
String |
Optional |
Object name prefix used in the redirection request |
||
ReplaceKeyWith |
String |
Optional |
Object name used in the redirection request. This parameter cannot be used together with ReplaceKeyPrefixWith. |
||
HttpRedirectCode |
String |
Optional |
HTTP status code in the response to the redirection request |
- ErrorDocument, IndexDocument, and RoutingRules must be used together and they cannot be used with RedirectAllRequestsTo.
- When ErrorDocument, IndexDocument, and RoutingRules are used together, RoutingRules can be null.
- You must set either these three fields or RedirectAllRequestsTo.
Returned Result (InterfaceResult)
Field |
Type |
Description |
---|---|---|
RequestId |
String |
Request ID returned by the OBS server |
Sample Code
obsClient.setBucketWebsite({ Bucket : 'bucketname', // RedirectAllRequestsTo : {HostName : 'www.example.com', Protocol : 'https'} IndexDocument:{Suffix:'index.html'}, ErrorDocument:{Key:'error.html'}, RoutingRules:[ {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'http',ReplaceKeyWith:'NotFound.html'}}, {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'https',ReplaceKeyWith:'test.html'}} ] },function (err, result) { if(err){ console.error('Error-->' + err); }else{ if(result.CommonMsg.Status < 300){ console.log('RequestId-->' + result.InterfaceResult.RequestId); }else{ console.log('Code-->' + result.CommonMsg.Code); console.log('Message-->' + result.CommonMsg.Message); } } });
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.