Print

Activate Permalinks On Staging Site

WP Staging Pro 2.8 and later allows you to keep the permalink settings.
Just activate it via WP Staging > Settings > Keep Permalinks

Whenever you create a new staging site, WP Staging will disable post name permalinks on the staging site to ensure that the staging site works properly on all server systems.

Usually, this is okay for a staging website. Often, there is just no technical need to activate custom permalinks to benefit from a staging site.

If you still like to activate permalinks on your staging site find out first what type of web server is running on your server or hosting plan.

You need to be able to access the admin dashboard of your WordPress staging site to be able to activate post name permalinks.

If you try to access your staging site admin dashboard and the staging site redirects you to the live site add the slug wp-admin to the end of the URL like https://example.com/stagingsite/wp-admin

This will allow you to access the wp-admin of your site.

(Such kind of redirect can happen if you use language plugins like WPML or Polylang which add a language slug to the URL. These plugins often need the permalinks activated)

Apache Web Server

If your website is served by the Apache web server chances are good that search friendly permalinks work without any additional work.

Just activate the permalinks from

Staging Site > wp-admin > Settings > Permalinks
 

Most often this is working very well from the beginning.

If this does not give the expected result and the links on the staging site are throwing an error 400, create a new .htaccess file and paste it into the root of the staging site by using an FTP program

The content of that file should look like this:

# BEGIN WordPress

RewriteEngine On
RewriteBase /staging/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /staging/index.php [L]

# END WordPress

Replace the bold text staging with the sub folder name where the staging site has been copied to.

Nginx Web Server

If you are using the Nginx web server there is only the advanced way to activate permalinks on the staging site.  Before you go that route, try to enable search friendly permalinks on the staging site by going to the settings page below:

wp-admin > Settings > Permalinks

Now check if this is works by opening the front page of your website and by clicking on any link. This is either working or not.

It works if the link is opened in a new window. If it does not open and returns a 404 error instead you need to follow the advanced way below.

Create a new server block in the nginx.conf which should be similar to the code below:

location /staging{
        try_files $uri $uri/ /staging/index.php?q=$request_uri;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        }

}

The path to the staging site must be adapted to your server as well as the path to the PHP socket file. This should give you only an idea of what to change. Do not use these values word by word.

Be aware that you need full access to your server to follow the steps above. If you have no clue what these lines do it might be best to ask someone to assist you with the modifications or just keep the permalinks disabled.

After doing that, the Nginx server needs to be restarted and you can enjoy your staging site with enabled custom permalinks.

Microsoft IIS

Create a new file named web.config in the subfolder of your staging site and paste the following XML into this file and then save it.

Change the term stagingsite to the subfolder name of your site.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="static" patternSyntax="Wildcard">
          <match url="*"/>
          <conditions>
	    <add input="{REQUEST_URI}" matchType="Pattern" pattern="/wordpress/*" negate="true" />	
 	    <add input="{REQUEST_URI}" matchType="Pattern" pattern="/wp-json/*" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="index.html" redirectType="Found"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  <location path="stagingsite">
    <system.webServer>
      <rewrite>
        <rules>
          <remove name="stagingsite" />
          <rule name="stagingsite" patternSyntax="Wildcard">
            <match url="*"/>
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
            </conditions>
            <action type="Rewrite" url="stagingsite/index.php" redirectType="Found"/>
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
  </location>
  <location path="wp-json">
    <system.webServer>
      <rewrite>
        <rules>
          <remove name="api" />
          <rule name="api" patternSyntax="Wildcard">
            <match url="*"/>
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
            </conditions>
            <action type="Rewrite" url="stagingsite/index.php" redirectType="Found"/>
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
  </location>
</configuration>