Forum
Help With Rewrite Rule
Currently I have category links in a sidebar for my blog to enable viewing only posts for that category.
The code for the link is
<a href="?cat=<perch:category id="catSlug" />"><perch:category id="catTitle" /></a>
Which displays as /news/?cat=my_blog_category, I would rather it showed as /news/my_blog_category
So I tried changing this in htaccess:
RewriteRule ^news/([a-zA-Z0-9-/]+)$ /news/?cat=$1 [L]
and the link to:
<a href="<perch:category id="catSlug" />"><perch:category id="catTitle" /></a>
But it does not work, anyone know how to do this? I know the rewrite is working as I have clean urls for the posts.
my_blog_category
contains underscores, but your regexp pattern doesn't include any.That was just a dummy category for example purposes!
So it might be /news/?cat=local-news
should match
Thats what I had to start with above, but it does not load the page with any perch articles.
/news/?cat=local-news works but the rewrite does not, any idea why its not working?
This is my whole news rewrite rule:
The post rules work okay.
You have the same pattern for the posts.
So should I change it to
and the link to
That would help.
Tried it and if I delete these it works:
But with these rules in it does not, any idea why?
Yes! You've got two patterns that match the same thing. Only the first will ever match.
But surely
Is a different pattern from
If not what is the pattern?
Yes, it is now. Put the most specific first. The former also matches the latter.
This really is beyond the scope of Perch support.
Thanks!! The order solved it, putting the category one first made the difference.
PS I realise its beyond your support and I was not necessarily expecting your help, was hoping someone else might have the answer. I spent ages trawling mod_rewrite docs but it was just the order that stopped it.