Forum

Thread tagged as: Problem

Clean URLs in Blog

Hi,

I've been following these steps for clean URLs on my blog: https://docs.grabaperch.com/addons/blog/examples/clean-urls-perch/

Got everything to work except preview an draft. It automatically adds /preview to the URL when clikcing on "Preview Draft", and the guide says that should do it. Any suggestions then?

Erick Green

Erick Green 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

The guide says

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.

Have you done that?

Show us your current rules if you have...

I have not set up any rules. The preview button already sends me to mydomain.com/blog/blog-title/preview.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to set up some rewrite rules on your server to handle those URLs.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Sorry, I meant .htaccess rules.

What happens now when you click on mydomain.com/blog/blog-title/preview ?

You need to set up a .htaccess rule to mydomain.com/blog/post.php?s=blog-title&preview=all

I get my 404 error page when i click on mydomain.com/blog/blog-title/preview. Is there a guide on how to set up this specific preview rule in .htaccess?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, in the article you linked to in your original question above.

You mean this?

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

Try this

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]

Got that to work but missing my stylesheet. Thanks Stephen!

What if I use Perch Runway code in my .htaccess? I also have a few sites with the blog app on my root folder, not inside a "blog"-folder.

# Perch Runway
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/dv-cms 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /dv-cms/core/runway/start.php [L]

Just make sure your css and js links are from root, that should fix it

 <script src="/assets/js/menu-script.js"></script>
 <link rel="stylesheet" href="/assets/css/menu-style.css">

NOT

 <script src="../assets/js/menu-script.js"></script>
 <link rel="stylesheet" href="../assets/css/menu-style.css">

That should work, thanks! Have to done the rewrite rules for preview drafts with Perch Runway?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Runway has routing built in, so you need to set up a route in the Control Panel.

What would this routing look like in Control Panel? Can you give me an example based on the .htaccess rule.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using Perch or Runway?

I'am using Runway.

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not of routes examples here: https://docs.grabaperch.com/addons/blog/runway/config/

Thanks! Sorry missed that page.