Archive REWRITE RULE needed [solved]

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Archive REWRITE RULE needed [solved]

Post by johncanary »

Hi,
I have setup my permalink structure as

Code: Select all

/%year%-%month%/%postid%-%post-title%
E.g.: From the error log I see that many people try to accessSerendipity delivers '404 Not Found' Status Error, but of course it redirects to the
Blog's home page.

Even though Garvin helped me earlier to add a shortcut URL like /post45/, /post95/,
I could not figure out how to rewrite those URLs properly. At this point I am pretty
sure that the PHP code will have to be adated, too.

I'd like to rewrite/redirect above URLs that they produce a '200 OK' Status and
deliver either the detailed or summary version of the monthly archive. The archive
URIs for my Blog setup are:from /2007-10/ and /2007-10/ with everything that does not start with a
numerical postid


Any help is
appreciated.

Yours John
Last edited by johncanary on Thu Nov 22, 2007 5:24 pm, edited 1 time in total.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Archive REWRITE RULE needed

Post by garvinhicking »

Hi!

How about this mod_rewrite rule:

Code: Select all

RewriteRule ^/([0-9]{4})\-([0-9]{1,2})/ /archives/$1/$2/summary.html [L,QSA]
?

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/
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Re: Archive REWRITE RULE needed

Post by johncanary »

garvinhicking wrote:Hi! How about this mod_rewrite rule:

Code: Select all

RewriteRule ^/([0-9]{4})\-([0-9]{1,2})/ /archives/$1/$2/summary.html [L,QSA]
? Regards, Garvin
Unfortunately it does not seem to be that easy. It simply loads the blog homepage without an error message. index.php doesn't accept the rewritten URL as 'archive'.

I started to look into index.php. The original request URI get's analized.

Code: Select all

f (preg_match(PAT_ARCHIVES , $uri, $matches) || isset($serendipity['GET']['range']) && is_numeric($serendipity['GET']['range'])) {
    $serendipity['view'] = 'archives';
    $_args = $serendipity['uriArguments'];

    /* Attempt to locate hidden variables within the URI */
    foreach ($_args as $k => $v){
        if ($v == PATH_ARCHIVES) {
            continue;
        }
        if ($v{0} == 'C') { /* category */
            $cat = substr($v, 1);
...
I'll have to look into include/genpage.inc.php, and include/functions_permalinks.inc.php for sure. The structure of the archive seems to be hardcoded. to /$archives_path/$year/$month/summary.html

Yours John
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Any more help?

Post by johncanary »

Any additional help still would be appreciated.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Any more help?

Post by garvinhicking »

Hi!

HOw about a hard redirect:

Code: Select all

RewriteRule ^/([0-9]{4})\-([0-9]{1,2})/ /archives/$1/$2/summary.html [L,QSA,R=302] 
?

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/
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Thank you!

Post by johncanary »

Hi Garvin!
External Redirection!
That's it. 8) That works fine, without having to touch any of the .php files.

I have altered the rule a bit:
  • Doing a 301 Permanent Redirect instead
  • Use a relativ path to have it work together with RewriteBase
  • Catch more 'mistyped URL' and exclude something that could be a valid URL to an
    entry (they begin with the numerical %id% after %year%-%month%/ in my case.
  • Decided to show the index page instead of the summary (has more keywords)
  • I put it after the ordinary Rewrite rule for archives.

Code: Select all

...
RewriteRule ^archives([/A-Za-z0-9]+)\.html index.php?url=/archives$1.html [NC,L,QSA]
RewriteRule ^([0-9]{4})-([0-9]{1,2})(/|/[^0-9].*)?$ archives/$1/$2.html [L,QSA,R=301]
...
Thanks again.
Yours
JohnCanary
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
Post Reply