Forum

Thread tagged as: Question, Configuration

Configure Preview URL's

Hi,

Today I have succesfully set-up my Mailchimp integration and added a sign up for to my list, excellent news! I have also got my URL rewriting working correctly but I'm not understanding what I need to add to the .htaccess file for the following section from the docs and why. I'd greatly appreciate it if you could let me know what I need to add to the file.


Preview URLs

Once URLs are rewritten, draft post preview is achieved by adding /preview to the end of your URL, so remember to add a rule for that. You should rewrite it to add the query string argument preview=all to the URL.


Look forward to hearing from you.

Regards

Rob

Rob Hawkins

Rob Hawkins 0 points

  • 7 years ago

You will need something like this in your .htaccess file

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

.... assuming that your posts are in /blog/

Hi Clive,

Thanks for the quick response. I've added this to the .htaccess file and then when I click preview in the "Admin" for a given blog post I get what looks to be the correct URL in the browser suffixed via /preview but the page as you will see is missing any styling etc...

As I've only just set the blog up this past week this is the first time I've tried to preview a post so am not sure what I'm supposed to see or if perhaps I need to set something else up for preview to work?

https://www.colconquerors.com/blog/2014-11-04-riding-a-guests-perspective/preview

Help appreciated.

Regards

Rob

Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you are rewriting URLs you need to link your stylesheets so they are root relative.

I think I understand but why does the post work when it's not in preview but when I preview it it's un-styled?

Can you given me an example of what you mean also?

Help appreciated.

This is how my stylesheets currently look so not sure what would need changing?

<title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?> - Colconquerors V-Zone</title>
<link href=../css/reset-min.css media=screen rel=stylesheet type=text/css />
<link rel=stylesheet href=../css/supersized.core-min.css type=text/css media=screen />
<link rel=stylesheet href=../responsive-nav-min.css>
<link rel=stylesheet href=../styles-min.css>
<link href=../colconquerors2014.css rel=stylesheet type=text/css />
<link rel=stylesheet href=../css/rrssb.css />
Drew McLellan

Drew McLellan 2638 points
Perch Support

<link href=/css/reset-min.css media=screen rel=stylesheet type=text/css />
<link rel=stylesheet href=/css/supersized.core-min.css type=text/css media=screen />
<link rel=stylesheet href=/responsive-nav-min.css>
<link rel=stylesheet href=/styles-min.css>
<link href=/colconquerors2014.css rel=stylesheet type=text/css />
<link rel=stylesheet href=/css/rrssb.css />

Thanks Drew, I've made those changes but guess I have to change all references within the stylesheet to be as such as well?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, within a stylesheet any url() paths are relative to the location of the stylesheet.

I've changed all reference now to be root specific.

When I view the post normally like this the layout of the page is good:

https://www.colconquerors.com/blog/2014-11-04-riding-a-guests-perspective

When I try it with /preview on the end like this there are problems with the layout and I also don't see any content when I view the source HTML from within the browser and not sure why this is?

https://www.colconquerors.com/blog/2014-11-04-riding-a-guests-perspective/preview

Hi Drew,

Not sure if you received my last post? I've take a look and it still doesn't make sense to me...

Help hugely appreciated, this could be the final thing before I can actually start to work on some good content :-)

Cheers

Rob

Ok so the layout thing is me I hadn't made the link to /blog/blog.css correctly. Now everything looks correct there's just no content when I add /preview on the end of the post link or click preview from the admin once the post is marked as draft.

Any ideas why the content is missing?

Help appreciated.

Cheers

Rob

What does your .htaccess file look like?

Thanks for helping.... here is mu .htaccess file:

redirect 301 /index.html https://www.colconquerors.com/index.php
redirect 301 /riding.html  https://www.colconquerors.com/riding.php
redirect 301 /camps.html https://www.colconquerors.com/camps.php
redirect 301 /chalet.html https://www.colconquerors.com/chalet.php
redirect 301 /prices.html https://www.colconquerors.com/prices.php
redirect 301 /feedback.html https://www.colconquerors.com/feedback.php
redirect 301 /contact.html https://www.colconquerors.com/contact.php
redirect 301 /sportives.html https://www.colconquerors.com/sportives.php


# Creates Search friendly URL's for Perch Blog
#
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
  RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]

</IfModule>
# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------

#
# These are pretty far-future expires headers
# They assume you control versioning with cachebusting query params like:
#   <script src="application.js?20100608">
# Additionally, consider that outdated proxies may miscache
#
#   www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

#
# If you don`t use filenames to version, lower the css and js to something like "access plus 1 week"
#

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"



# Your document html
  ExpiresByType text/html                 "access plus 0 seconds"

# Data
  ExpiresByType text/xml                  "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType application/json          "access plus 0 seconds"

# RSS feed
  ExpiresByType application/rss+xml       "access plus 1 hour"

# Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week"

# Media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType video/ogg                 "access plus 1 month"
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType video/mp4                 "access plus 1 month"
  ExpiresByType video/webm                "access plus 1 month"

# HTC files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 month"

# Webfonts
  ExpiresByType font/truetype             "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
  ExpiresByType text/css                  "access plus 1 week"
  ExpiresByType application/javascript    "access plus 1 week"
  ExpiresByType text/javascript           "access plus 1 week"

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try switching the rules around, so the more specific rule comes first:

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]

Try putting the preview rule before the post rule

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]

Two perfect answers!!

Clive, Drew - Thanks very much that all looks to be working now.

I'm guessing now that I'm using these URL's that each of my blog pages I use must always have root paths specified so as at now (index.php, post.php & archive.php)?

Cheers

Rob

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should always do that anyway.

Ok Drew thanks for the tip...

On the same issue I've come across another issue...

I've noticed that when a blog post link is cut and past and has a trailing "/" at the end like the following example when you then are directed to the blog post the categories on the sidebar do not work, rather take me to my page not found page.

The categories don't work for this link:

https://www.colconquerors.com/blog/2014-11-04-a-change-of-scenery-this-winter/

But when like this are as before the changes to the new style URL's. This is important because when shared via the social media link items the link has the trailing "/"

Help appreciated.

Cheers

Rob

Hi Drew,

I think I know the problem but I can't seem to make the change to correct it. WHen I look at the links in the sidebar they go to https://www.colconquerors.com/archive.php?cat=training when in fact this must now be as follows I think. Problem is I made the change below in my category.html and category_link.html file and the links in the side bar still say the non /blog version.

What am I doing wrong?

<perch:before><ul></perch:before>
    <li>
        <a href="/blog/archive.php?cat=<perch:category id="catSlug" type="slug" for="catTitle" order="2" />">
            <perch:category id="catTitle" type="smarttext" label="Title" required="true" order="1" />
        </a>
    </li>
<perch:after></ul></perch:after>

Problem fixed, I just opened a blog post and saved it and things switched over.

Cheers

Rob