Use Apache .htaccess to allow request if variable is presented

I need to hide the site from guest users and show it just if preview variable is presented or the user is in wp-admin folder.

Now in .htaccess I have

Read More
    RewriteEngine On
    RewriteBase /

    RewriteRule (.*)/wp-admin(.*) - [QSA,L,NC]

    RewriteCond %{REQUEST_URI} !/wp-admin [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteRule . / [L]

It works well for the task condition. I need to check if there is a preview GET parameter is presented and allow such request to be handled by index.php. The request can look like

    http://domain.com/about/?preview_id=152&preview_nonce=657d480c2c&preview=true

Of course if preview variable exists all assets should be handled in a normal way.

How can it be done?

Related posts

1 comment

  1. You can add one more RewriteCond for preview parameter:

    RewriteEngine On
    RewriteBase /
    
    RewriteRule (.*)/wp-admin(.*) - [L,NC]
    
    RewriteCond %{QUERY_STRING} preview [NC]
    RewriteRule ^ index.php [L]
    
    RewriteCond %{REQUEST_URI} !/wp-admin [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteRule . /index.html [L]
    
    # rest of the rules 
    

Comments are closed.