There’s a couple of common situations where you want to be able to easily view your website, but you can’t yet because your domain isn’t pointing to your hosting account:
- Development: The site is still being developed and so the domain is pointing to a different hosting account where the prior live site resides. (Your development site is not live to the public at all).
- Testing: You have migrated the site content, and you wish to test to be sure it’s working smoothly before changing the DNS.
- Waiting: You want the site to go live now, but you’re still waiting on the name server or DNS record changes to propagate to your Internet provider.
Regardless of which situation applies to you, it can be assumed that visiting the website in a browser either isn’t working at all, or is showing a different (older/live) version of the site, yet you still want access now.
Time needed: 15 minutes.
There’s a few tricks for this! You can:
- Use the Plesk preview URL
This is the quickest option, but if you’re using WordPress, it requires adjustments to the wp-config.php to work smoothly.
- Use a subdomain instead
This option is easy to implement, but requires that we host the DNS or that you have access to the DNS host to manually create records.
- Use a HOSTS file override
This is a bit harder to implement, however once you’ve made the necessary adjustments to your computer, it is the best way to develop a website that’s not live.
Scroll to your preferred option to learn how it’s done.
Option 1: Use the Plesk preview URL
To find the Plesk preview URL, log in to Plesk then look right under the blue header where it shows your domain name. You’ll find a button that says “Preview” with an eye icon. Click it to be taken to your site via the preview URL.
Using the Preview URL with WordPress
There’s a couple things to watch out for when using the preview URL. If you notice the same issues occurring with web apps other than WordPress, the solutions should be similar.
- WordPress, will ‘break’ you out of the preview URL and attempt to force you to the live site when you click on any links on the site. This isn’t very helpful, as you want to remain viewing/working on the site at the preview URL, not the live site!
- Any media you upload or links you create in WordPress while using the preview URL will be hard-coded with the preview URL and not your live URL, which may cause problems when you go live. Many web hosts (including costly managed WordPress hosts) provide no mechanism whatsoever to resolve this problem, but they should, because it can cause some serious problems with your website, especially in the long-run.
Tip: using a HOSTS file override (Option 3 below) will avoid both of these issues and while HOSTS file overrides are more difficult to set-up, they make rolling out the development site a lot simpler. Because of this we recommend using a HOSTS file override for development and only using the preview URL for showing your work to clients (read only).
To work around these issues, complete the following two steps to instruct WordPress to allow both the live URL and the preview URL when viewing the site and to use relative URLs for media and when creating links in the WordPress admin.
Use the Plesk File Manager to copy and paste the following code exactly as it is (do not replace variables with actual values) above the line in wp-config.php that says:
/* That's all, stop editing! Happy blogging. */
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME']); define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_CONTENT_URL', '/wp-content');
Login to the WordPress admin at <preview_url>/wp-admin. Go to Plugins > Add New and search for “Absolute <> Relative URLs” and install and activate this plugin.
Although you won’t *see* a difference while working in the admin, it will save all links as relative URLs to the database, but present them on-site as absolute URLs to keep WordPress happy. When you make the site live, all URLs will switch to the live domain automatically.
Upon Rollout: It’s very important for SEO to ensure you remove the custom WP_HOME and WP_SITEURL configuration values when the site goes live. However, do not remove the WP_CONTENT_URL value, otherwise you may experience odd issues with media. You should also be able to remove the “Absolute <> Relative URLs” plugin at this time and all future URLs will be stored in the DB as absolute values using the live domain name.
Option 2: Use a Subdomain (Intermediate)
If your reason for wanting to not make your site live yet is because you’re planning on developing a new site first, this option is a good one for you.
- In Plesk, choose the option to Add a Subdomain and call it something like ‘dev’, ‘staging’, ‘new’, or ‘preview’.
Please note: if your DNS is not hosted with us, you’ll now need to login to your DNS host (often the registrar) and add a new DNS record of type “A” that points to the IP for your hosting with us as shown in Plesk. It may take a few hours for the new DNS record to take effect.
- Install WordPress to the new subdomain using 1-click web apps (or clone it from the main site if you don’t wish to start from scratch).
When you’re ready to take the site live, use our 1-click web apps utility to clone it from the dev subdomain over to the main domain. At this point, if you haven’t already done so, you can reconfigure your domain at the registrar or DNS host to make it live.
Option 3: HOSTS File Override (Intermediate)
Quick Intro to DNS
Whenever you visit a website like websavers.ca or google.com, your computer asks your DNS server, usually supplied by your Internet provider, for the numerical IP address of the server the site lives on (they look like this: 22.214.171.124). When the domain is either not yet registered or not yet pointing to your Websavers hosting plan, your DNS servers are either going to say “Sorry, I don’t know” or provide the currently live IP address, rather than the one for your Websavers hosting.
The following steps will show you how to instruct your computer to use a specific IP/server every time you visit the website, overriding the currently live IP address.
Overriding DNS with the hosts file
Windows, Linux and macOS all use a special file known as the hosts file to manually convert names to numbers. Your computer looks at the hosts file before checking with your DNS servers to get the matching IP, so when you want to instruct your computer what server your website resides upon, this is the file to use!
Here is the location of the file on Windows, Linux and macOS:
How do I use my hosts file?
The file may have some information in it at the top – normally information about how to use the file. The key to entering info accurately in the hosts file is by using the following format:
[ServerIPAddress] [DomainName1] [DomainName2]
So, for example, websavers.ca might look like this:
126.96.36.199 websavers.ca www.websavers.ca
Note: I’ve included both websavers.ca and www.websavers.ca just in case we try to access the site by either method. You should do the same, otherwise you might see some strange results.
You can edit this file directly using your favourite text editor, but note that it’s not always easy to access their locations. Windows typically hides that system folder, and macOS has it classified as part of its Unix subsystem which makes it unreachable in the file browser (Finder). We’ve listed a few handy utilities below for each operating system that will make it easier to edit your hosts file.
Handy hosts file editing tips
If you’re using a Mac, head on over to the Gas Mask Google Code project page and get installing!
This app opens up your hosts file automatically and allows you to save it by writing over the current file. You also have the option of saving multiple hosts files and easily switching between them. This way you can save a default as well as a different one to easily activate and deactive each site you’re working on. Simply create a new one and throw in the IP and site name using the format above. Select the host file you want active on the left, then click the checkbox in the toolbar to activate it. All set!
[Advanced] You could alternatively use a terminal-based text editor like vim. Open terminal and run:
But be warned, vim isn’t the easiest to use! You should look up a vim tutorial before going with this option.
On Windows you can install an app called Windows Hosts File Editor and use that to help you edit the hosts file.
Alternatively you can manually edit the file with Notepad. Here’s how:
- Open the Start Menu and search for Notepad
- When you see Notepad in the results, right click and choose “Open as Administrator” (say yes to approve the security prompt)
- Choose File > Open from the menubar and navigate to the directory shown above
- The directory will appear to be empty. On the far right side of the “File name:” box at the bottom of the window, click the drop down that sats “Text Documents (*.txt)” and select the option for “All Files”. This will show the hosts file in the list above.
- Double click on the hosts file to open it
- Below the last line with a # in front of it, type in your entry using the same pattern as shown above — [IP] [Domain]
- Choose File > Save from the menu
If you get a Forbidden error about permissions indicating that “You do not have permission to access this document”, then you skipped step #2. You must run Notepad as administrator in order to have permission to update the file. Please close Notepad and start again.
Have any trouble making these apps work? Have an even better app to edit the HOSTS file? Something wrong with the directions? Use the comments below to tell us!
THEME RESOURCE PROBLEMS: If you are using the preview URL with our wp-config.php overrides, and you notice theme resources not loading properly on both the front-end and in the WordPress admin, it’s because you placed the overrides at the very bottom of the wp-config.php file — they must be placed above the “stop editing” warning as described above!