Forum

Thread tagged as: Question, Blog

Preview for draft posts not showing up

Hello,

I've successfully rewritten my urls however the preview for draft posts aren't showing the post correctly. The line I have in my .htaccess is:

RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]

any ideas?

Chima Nwosu

Chima Nwosu 0 points

  • 4 years ago
Simon Clay

Simon Clay 127 points

The syntax looks right. Do 'published' posts view correctly? What order do you have it in your htaccess file?

Hey Simon,

htaccess below

<IfModule mod_expires.c>
RewriteEngine on

RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]
RewriteRule ^blog/category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?cat=$1&page=$2 [L]

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1&page=$2 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]

RewriteRule ^/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?year=$1&page=$2 [L]

RewriteRule ^(css)($|/) - [L]
RewriteRule ^(perch)($|/) - [L]
RewriteRule ^(images)($|/) - [L]
RewriteRule ^(js)($|/) - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Duncan Revell

Duncan Revell 78 points
Registered Developer

This line

RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]

needs to be before this line

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

And this line

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1&page=$2 [L]

isn't going to work as there isn't a second set of ( ) to pass to $2 - the page thing will never work.

You'll probably have to change the order of your blog/category rules too.

Hey Duncan,

Thank for this, I've done some rearranging and still haven't had any luck. Code is below:

<IfModule mod_expires.c>
RewriteEngine on

RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1&page=$2 [L]

RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]
RewriteRule ^blog/category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?cat=$1&page=$2 [L]

RewriteRule ^/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?=$1 [L]
RewriteRule ^/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?=$1&page=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>