This post is applicable for AEM (adobe CQ).
As AEM provide couple of ways to preview your pages; but sometime business user require your actual preview like your end site with all redirects, re-write and vanity URL’s.
You can achieve in two ways as follows :
- Install a separate publish instance and use as stage environment. But this require to add a new instance into your infrastructure and it will cost also.
- Other way you can utilize your author instance by handling through apache virtualhost, rewrite and dispatcher configuration
I opt option #2 to implement my preview instance using below configuration
- Create a readonly users in author instance and generate a authentication token and set into below configration.
<VirtualHost *:80>
ServerName <<previewsitename>>
DocumentRoot <<doctoot>>
DirectorySlash Off
RewriteEngine on
<Directory <<doctoot>>>
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
<IfModule disp_apache2.c>
SetHandler dispatcher-handler
ModMimeUsePathInfo On
</IfModule>
AllowOverride none
</Directory>
SetEnvIf Remote_Addr “127\.0\.0\.1” localrequest
RequestHeader set Authorization “<<authorization tocken>>” env=!localrequest
# Handle request with slash
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} !^/etc/designs/<<yourdesign>>
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} .*/$
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*)/$ $1 [R=301,NE,QSA]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)\.html$ $1 [R=301,NE,QSA]
# Handle requests no extension
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} !^/etc/designs/<<yourdesign>>
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^/(.*)$ /content/<<sitename>>/$1.html?wcmmode=disabled [PT,L,QSA]
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
#RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} !^/etc/designs/<<yourdesign>>
RewriteRule ^/(.*)$ /content/<<sitename>>/$1?wcmmode=disabled [PT,NE,L]
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/content/<<sitename>>/(.*)$ /$1 [R=301,NC,NE,L]
</VirtualHost>
if above configuration looks complex; please find easiest URL rewrite setting
First add in request header
Header add SM_USER “aempreview”
RequestHeader set SM_USER “aempreview”
Second updated the rewrite condition
RewriteRule ^/content(.*)\.html$ /content$1\.html?wcmmode=disabled [PT,L]
Hope this helps !