• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

Question Can I create a service plan for redirects?

Reinier Post

New Pleskian
Server operating system version
Ubuntu 22.04
Plesk version and microupdate number
Obsidian, 18.0.71 Ubuntu 22.04 1800250729.09
We sometimes create subscriptions that do nothing but host an HTTP redirection.

I create these by creating a regular web hosting subscription (including a Linux user and files on the file system), then changing the hosting type to 'forwarding' (which removes the files and the Linux user).

Is there a way to define a service plan specifically for such redirections? Advantages:
  • It would save work: it would allow me to create the redirection straight away.
  • I can see by its service plan that it's a redirection.
 
Is there a way to define a service plan specifically for such redirections?

To my knowledge there is not. However, if you have a little bit of shell scripting knowledge you could automate the process with help of the event manager in Plesk. From the top of my head, as a general guide, I think this would involve:
  • Setting up a service plan to use for redirects
    I realize that might be confusing, since you can't define redirects in service plans. In this case the service plan is only used as an identifier for the script to modify the hosting settings of a subsciption that uses this particular service plan.
  • Create a bash/shell script that gets called by an event (I think the "Default Domain Created" event) you setup in the event manager. This will call the script every time a subscription gets added. With this script you then:
    • check if the subscription uses the previous create service plan. If it does, than;
    • use the Plesk CLI to change the hosting type of type to direct and set an redirect URL.
The caveat being that this only works when you add a new subscription. But you can setup an other event ("Service Plan of Subscription changed") to call the same script to be sure this also works when the service plan gets changed to the redirect subscription for an existing subscription.

Example script:
Bash:
#!/bin/bash

# Get subscription info
SUBSCRIPTION=$(`/usr/local/psa/bin/subscription --info ${NEW_DOMAIN_NAME}`)

# Check if subscription uses your "redirect" service plan
if [[ "$SUBSCRIPTION" == *"NAME_OF_YOUR_SERVICE_PLAN"* ]]; then  
     # Change hosting type of domain to redirect and set redirect URL
      /usr/local/psa/bin/site -u  ${NEW_DOMAIN_NAME} -hst_type std -target_url https://example.net
fi
Change NAME_OF_YOUR_SERVICE_PLAN in the script to the actual name of the service plan you created for the redirect. The name is case sensitive.

I haven't tested any of this and there might be other ways to accomplish the same, but this came to my mind first.
 
Last edited:
Back
Top