Page 1 of 1

Archive REWRITE RULE needed [solved]

Posted: Sun Nov 04, 2007 3:37 pm
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

Re: Archive REWRITE RULE needed

Posted: Mon Nov 05, 2007 10:15 am
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

Re: Archive REWRITE RULE needed

Posted: Tue Nov 06, 2007 3:29 am
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

Any more help?

Posted: Thu Nov 22, 2007 12:58 pm
by johncanary
Any additional help still would be appreciated.

Re: Any more help?

Posted: Thu Nov 22, 2007 2:01 pm
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

Thank you!

Posted: Thu Nov 22, 2007 5:00 pm
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