Custom Category Links

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
macavenger
Regular
Posts: 9
Joined: Wed Mar 07, 2007 11:40 pm
Location: Fairbanks, AK
Contact:

Custom Category Links

Post by macavenger »

Short version: I want to put a custom link on my web site, such as http://izzy.homeip.net/nagios that points to a Serendipity category such as index.php?/categories/8-Nagios, in the same way that /categories/8-Nagios does - i.e. when you type that link, you get the category page, even though the address remains /nagios. Is this possible, and if so, how?

Long version: I have serendipity set to use mod_rewrite to generate pretty URL's for categories, posts, etc. This is working fine. In looking over the rewrite rules generated in the .htacces file, my first thought was that I could simply add another that re-wrote nagios to index.php?/categories/8-Nagios. No luck though. The rule was matched, and according to the logs the url was re-writen properly, but I wound up at the index page rather than the category page. At this point I have checked everything under the sun, and as far as I can determine the rewrite rule is correct. So is there a different approach I should be taking here, or am i just missing something? Thanks.

Israel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Custom Category Links

Post by garvinhicking »

Hi!
macavenger wrote:Short version: I want to put a custom link on my web site, such as http://izzy.homeip.net/nagios that points to a Serendipity category such as index.php?/categories/8-Nagios, in the same way that /categories/8-Nagios does - i.e. when you type that link, you get the category page, even though the address remains /nagios. Is this possible, and if so, how?
No, you can't really do that.

The reason is that serendipity matches in index.php on the category permalink. So if your URL is "/nagios" s9y will use that one, and can't match it to any category, and then display the overview page.

A mod_Rewrite rule like you maybe tried:

Code: Select all

RewriteRule ^/nagios$ /categories/8-Nagios [L,QSA]
Would not change the REQUEST_URI to /categories/... - you might be able to use SetEnv or so to change REQUEST_URI to /categories/8-Nagios then, but I don'T really know how. You could patch such a comparison to your index.php:

Code: Select all

if ($_SERVER['REQUEST_URI'] == '/nagios') {
    $_SERVER['REQUEST_URI'] = '/categories/8-Nagios';
}
as one of the first lines.

You could of course change the permalink patters to not use /categories/%id%-%title% but only "/categories/%title%". But you can'T remove the prefix '/categories/' in the path, because s9y needs to have a distinct path to access categories.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
macavenger
Regular
Posts: 9
Joined: Wed Mar 07, 2007 11:40 pm
Location: Fairbanks, AK
Contact:

Thanks

Post by macavenger »

Thanks for the information. Putting that if block into the index.php file had the desired effect. I was wondering though if there might be a way to generalize the code? specifically, as it now stands, /nagios !=/Nagios != /Nagios/, so if I want it to be as robust as possible I would need four separate if blocks to cover all the possibilities. Is there some way to use a regexp or the like in PHP? I don't really know PHP at all, thus the question. Thanks again!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Thanks

Post by garvinhicking »

Hi!

Yes, a PHP code like:

Code: Select all

if (preg_match('@/Nagios/?@i', $_SERVER['REQUEST_URI'])) {
 ...
}
will do that for you :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply