Print

Activate Permalinks On Staging Site

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 appropriately on all server systems.

Since WP STAGING 2.8, You can tell WP STAGING to use the same post name or custom permalink structure on the staging site as used on the production site.

You can activate this option at WP Staging > Settings > Keep Permalinks and by creating a new staging site. This needs to be supported by your browser! If it does not work, disable that option and create a new default staging site.

Usually, that works well for a staging website. Often, there is no technical need to activate custom permalinks to benefit from a staging site.

If you still like to activate custom permalinks on your staging site, determine what type of web server runs on your server or hosting plan.

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

If you try to access your staging site’s 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

That will allow you to access the wp-admin of your website.

(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 the Apache webserver serves your website, the 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 subfolder name where the staging site has is copied to.

Nginx Web Server

If you use the Nginx web server, there is only an 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

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

It works if the link opens 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?$args;

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

}

Replace staging with the path to your staging site. Also, change the path to the PHP socket file if it is different. That 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 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.

Bitnami (Apache)

If you use WordPress in a Bitnami instance, you need to take extra steps.

Post-name permalinks are not supported out of the box on WordPress Bitnami instances because Bitnami does not use .htaccess in the root folder of the website. It ignores any .htaccess file there.

Bitnami does not use the default .htaccess file in the root of your website; instead, all the htaccess configurations are added to a file called: /opt/bitnami/apps/APPNAME/conf/htaccess.conf.

So if you want to make permalinks working, you will need to modify the htaccess.conf

Go to that file and add the following to it:

<Directory /opt/bitnami/apps/wordpress/htdocs/STAGING>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /STAGING/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /STAGING/index.php [L]
</IfModule>
</Directory>

Important: Rename the word STAGING to the folder name of your staging site!

Another option would be to keep the permalinks on the plain settings, and then you do not need to change the htaccess.conf at all.

Microsoft IIS

Create a new file named web.config in the subfolder of your staging site and paste the following XML into this file, 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>
Updated on November 11, 2020