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:
// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
'key' => '*** Provide your Access Key ***',
'secret' => '*** Provide your Secret Key ***',
'endpoint' => 'https://your-endpoint'
] );
$resp = $obsClient->setBucketWebsite( [
'Bucket' => 'bucketname',
// Configure the default homepage.
'IndexDocument' => ['Suffix' => 'index.html'],
// Configure the error pages.
'ErrorDocument' => ['Key' => 'error.html']
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
Configuring Redirection Rules
Sample code:
// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
'key' => '*** Provide your Access Key ***',
'secret' => '*** Provide your Secret Key ***',
'endpoint' => 'https://your-endpoint'
] );
$resp = $obsClient->setBucketWebsite( [
'Bucket' => 'bucketname',
// Configure the default homepage.
'IndexDocument' => ['Suffix' => 'index.html'],
// Configure the error pages.
'ErrorDocument' => ['Key' => 'error.html'],
// Set redirection rules.
'RoutingRules' => [
['Condition' => ['HttpErrorCodeReturnedEquals' => 404], 'Redirect' => ['Protocol' => 'http', 'ReplaceKeyWith' => 'NotFound.html']],
['Condition' => ['HttpErrorCodeReturnedEquals' => 404], 'Redirect' => ['Protocol' => 'https', 'ReplaceKeyWith' => 'test.html']]
]
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
Use the RoutingRules parameter to specify redirection rules for a bucket.
Configuring Redirection for All Requests
Sample code:
// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
'key' => '*** Provide your Access Key ***',
'secret' => '*** Provide your Secret Key ***',
'endpoint' => 'https://your-endpoint'
] );
$resp = $obsClient->setBucketWebsite( [
'Bucket' => 'bucketname',
'RedirectAllRequestsTo' => ['HostName' => 'www.example.com', 'Protocol' => 'http']
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
Use the RedirectAllRequestsTo parameter to set redirection rules for all requests for accessing a bucket.
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.