URL issues running Wordpress with Plesk SitePreview

If you are having trouble setting up a Wordpress installation with Plesk's Sitepreview, the following may help (and may also apply to other systems that give you a temporary URL to test sites before they go live).

Plesk is a piece of software which provides a straightforward front-end to manage a webserver, and is used by many ISPs to allow customers to manage their own servers.

SitePreview is a function of the Plesk control panel which allows you to view a site via a temporary URL before it goes live. This way you and your clients can view and tweak the site before you release it to the wild by putting it on a published URL.

The normal URL format which Plesk uses for SitePreview is of the form: http://xxx.xxx.xxx.xxx/$sitepreview/mydomain.com/

where xxx.xxx.xxx.xxx is the IP address of the server, and mydomain.com is the name of the site in Plesk (and the ultimate permanent URL). The problem with viewing a Wordpress site at a SitePreview URL is that Wordpress strips out the $ (dollar) sign, and other special characters, from URLs. This is normally sensible behaviour as the dollar sign would normally not appear in URLs, but it breaks SitePreview, as it begins to return URLs like http://xxx.xxx.xxx.xxx/sitepreview/mydomain.com/ (note no $ sign), which will give you a 404 Page Not Found error.

The first place I noticed this was when saving the main settings page. When you save this page, Wordpress strips out the $ from the two URL fields. I haven't looked for the code which does this, but it is easily fixed by using PHPMyAdmin to edit the wp_options table in your Wordpress database (the wp_ may be something else depending on the table prefix you set for your tables in the wp-config.php file). The two records in this table which you have to correct are the ones where - option_name = 'home' - option_name = 'siteurl' The second place you may have a problem is when using the admin screens.

When Wordpress creates the URLs for the javascript files which are required for the 'Visual' mode of the page editor to work, it again strips out those dollar characters. This issue can be resolved by editing the function clean_url, currently found in wp-includes/formatting.php.

Early on in this function is the line: $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@()]|i', '', $url);

Just change this to:

$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@()$]|i', '', $url);

i.e. add the $ sign just before the closing square bracket - the characters enclosed in this set of brackets will not be replaced in URLs.

This may have other implications I haven't discovered yet, so I would advise this as a temporary fix which should be removed when your site goes live. If you discover any other issues or solutions with using Wordpress and Plesk's SitePreview, please leave a comment below.