Forum

Thread tagged as: Problem, Blog

Problem rewriting blog urls

This is a last resort (I have tried everything I can think of including copying directly from the Perch documentation), so sorry if I am missing something obvious.

Can anyone shed any light as to why my .htaccess RewriteRules are not working for urls to categories, authors etc (clean post urls are fine).

My .htaccess file has the following (only showing what I am using for category urls to keep it short):

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ $1.php [L,QSA]

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

An example of a category link as output to the page:

<a href="/blog/topic/business">Business (1)</a>

All I get when I click on one of these links is what appears to be a blank single post page (no post is displayed but I know it is a single post page as my Disqus comments form is displayed). I have even tried changing the redirect to be to a general page on the website and still I get exactly the same.

I am totally confused as I don't normally have problems with rewriting urls and cannot for the life of me work out was is going wrong here.

Emma Davis

Emma Davis 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It could be an ordering issue. Try placing your rules above the catch-all. Most specific rules first.

Emma,

Rewriting URL's can be a pain. You can try this I know these work, plus a lot of time it comes down to the order. If you put # in front of the ones you know are working it can help you better troubleshoot what is going on when it comes to rewriting them.

<IfModule mod_rewrite.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 ^category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]
    RewriteRule ^tag/([a-zA-Z0-9-/]+)$ /blog/archive.php?tag=$1 [L]
</IfModule>

I've got the same problem as Emma. Brandon's code do not work for archive.php (but ok for blog post). Did you find a way ?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Christophe - I would suggest starting your own thread, including your rewrite rules and explaining how your site is structured.