Forum

Thread tagged as: Problem

Issues with url rewrite

OK, so I have something weird going on here and am so tired no that I am probably missing the obvious. I have this all set up in exactly the same way as I do on another site (where it works just fine although for a list and detail page, not a blog like here).... but it just won't work. It was all working fine until I then had issues rewriting the urls for the blog posts themselves. I got that bit working and this bit broke. However, even stripping out the post url rewriting, it still isn;t working and I don't knwo what I did to break it!

So, I have two categories set up - Industry News and Blog (under the set blog, so blog/industry-news and blog/blog). Each blog post is asigned to one of these categories. Then on the blog index page (news/index.php) I have some links at the top: All, Industry News and Blog which will filter the posts to show latest posts from all or either of the two categories.

index.php:

if (perch_get('cat')) {
PerchSystem::set_var('current_category', perch_get('cat').'/');
} else {
PerchSystem::set_var('current_category', 'all');
}
perch_categories();

    if (perch_get('cat')) {
        perch_blog_custom(array(
    'count' => 10,
    'sort'  => 'postDateTime',
    'sort-order' => 'DESC',
    'category' => perch_get('cat'),
     'template' => 'post_in_list.html',
));

       } else {
perch_blog_custom(array(
    'count' => 10,
    'sort'  => 'postDateTime',
    'sort-order' => 'DESC',
     'template' => 'post_in_list.html',
));
    }

category.html:

<perch:before><ul id="cats">
<li <perch:if id="current_category" match="eq" value="all">class="selected"><span>All</span><perch:else />><a href="/news/">All</a></perch:if></li></perch:before>
<li <perch:if id="catPath" match="eq" value="{current_category}">class="selected"><span><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></span><perch:else />><a href="/news/<perch:category id="catSlug"  />"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a></perch:if>
</li>
<perch:after></ul></perch:after>

My htaccess:

Options +FollowSymLinks 
RewriteEngine on 

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

Now, the category links correctly show /news/industry-news/ and /news/blog/ however, they redirect to /news/industry-news/?cat=industry-news ! For a start it is supposed to be the catPath but doesn't include the set. Secondly why on earth is it redirecting there?! The posts on the page are correctly filtered to the category.

This is so frustrating as it was working before and I have now spent hours going round in circles wondering where it broke!

Lisa Morena

Lisa Morena 1 points

  • 4 years ago

OK, so if I change the links in category to go to bob/ instead of news/ and update the redirect as well, it works. What is wrong with news/?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Drew has written an article on URL rewriting which may help you https://24ways.org/2013/url-rewriting-for-the-fearful/, we aren't able to assist with all the individual server configurations out there however. It's really outside the scope of Perch support.

A general web development site such as StackOverflow would be a better place to ask this kind of question.

I should have called it a day many hours before I did.... it was all due to a missing trailing slash on the category template url! It was always going to be something simple!