Setting Website Hosting
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
You can call ObsClient.setBucketWebsite to set website hosting for a bucket.
Configuring the Default Homepage and Error Pages
Sample code:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
WebsiteConfiguration config = new WebsiteConfiguration();
// Configure the default homepage.
config.setSuffix("index.html");
// Configure the error pages.
config.setKey("error.html");
obsClient.setBucketWebsite("bucketname", config);
Configuring the Redirection Rules
Sample code:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
WebsiteConfiguration config = new WebsiteConfiguration();
// Configure the default homepage.
config.setSuffix("index.html");
// Configure the error pages.
config.setKey("error.html");
RouteRule rule = new RouteRule();
Redirect r = new Redirect();
r.setHostName("www.example.com");
r.setHttpRedirectCode("305");
r.setRedirectProtocol(ProtocolEnum.HTTP);
r.setReplaceKeyPrefixWith("replacekeyprefix");
rule.setRedirect(r);
RouteRuleCondition condition = new RouteRuleCondition();
condition.setHttpErrorCodeReturnedEquals("404");
condition.setKeyPrefixEquals("keyprefix");
rule.setCondition(condition);
config.getRouteRules().add(rule);
obsClient.setBucketWebsite("bucketname", config);
Configuring Redirection for All Requests
Sample code:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
WebsiteConfiguration config = new WebsiteConfiguration();
RedirectAllRequest redirectAll = new RedirectAllRequest();
redirectAll.setHostName("www.example.com");
redirectAll.setRedirectProtocol(ProtocalEnum.HTTP);
config.setRedirectAllRequestsTo(redirectAll);
obsClient.setBucketWebsite("bucketname", config);
Last Article: Website File Hosting
Next Article: Viewing Website Hosting Settings
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.