Page 1 of 1

staticpages and index.html

Posted: Fri May 26, 2006 5:17 am
by ghoti
Is there a way to use a "directory" in a URL without a virtual filename when using staticpages? I am working on recreating (and of course expanding) an existing website, and I have a few URLs there that are just domain.org/directory/. I tried creating a static page that uses directory/index.html as its path, and that works, but it doesn't respond to pointing my browser at directory/. Is there some htaccess magic or something that I could use for that? The problem is also that s9y doesn't consider this as an error, but simply serves up the home page. I think I'd rather get a chance for some error handling, either by having a plugin look for the page, or by showing an error page.

Re: staticpages and index.html

Posted: Fri May 26, 2006 2:49 pm
by garvinhicking
Hi!

The ".html" is required to match the rewriteRules. Using a wildcard "/" regexp would then match too many URLs, so a restriction to ".html" is actually required and I don't see a good way to work around that.

BTW, if s9y serves such pages, you'll notice that it throws a HTTP 404 error. But in the past people enjoyed the fact that instead of an empty 404 page the user sees the blog page.

You can use a plugin to handle such 404 requests! Look at the index.php file and search for "404". It calls the genpage.inc.php file, which executes a plugin hook, and there you can catch a 404 by either using the new $serendipity['view'] = 404 variable (1.0beta"4" or 1.1-alpha nightlies) or by looking at the various $serendipity['GET'] variables if they're set (Because genpage is also called for "valid" pages).

HTH,
Garvin

Posted: Fri May 26, 2006 5:40 pm
by ghoti
Thank you, garvin! Where can I get 1.0b4? I can only find links to 1.1 on the s9y pages. I think I'd rather play with 1.0 for now, rather than jump to 1.1 ...

Posted: Fri May 26, 2006 5:53 pm
by garvinhicking
Hi!

You'd need to fetch 1.0beta4 from SVN, as no release file has been bundled for that, and it's a bit of work for me to do so.

Else you can fetch the 1.1 snapshots?

Regards,
Garvin

Posted: Fri Jul 07, 2006 5:08 am
by ghoti
Garvin, I managed to write a plugin that gets the genpage hook callback, and that can tell whether there's a 404 or not. Now how do I make Serendipity jump to another page, or alternatively, replace the location it is fetching the page data from? Can I still make it look at a different page at this point?

Posted: Fri Jul 07, 2006 11:58 am
by garvinhicking
Hi ghoti!

When the genpage hook is called,it usually means that index.php already has set all variables for the display logic, and it might be hard to get the desired target page.

You have two options:

1. Do a header('Location: ...') redirect to the page you need.

2. Set the right HTTP headers and set the $serendipity[] variables to what you need, and you MIGHT get what you want. Check the index.php workflow of how and where genpage.inc.php is called, and then see on how the page you want to target sets variables that you could try to do on your own.

3. Instead of using the genpage hook, you might want to use frontend_configure. There you can put your code to check what page you might want to call up, and then Modify the $_SERVER['REQUEST_URI'] to point to the file you then want to emit. This way you effectively change how index.php handles the current page cycle.

In the end, it would be important to know on where you want to redirect to?

Best regards,
Garvin

Posted: Tue Jul 11, 2006 4:21 am
by ghoti
Thank you, garvin! I did it using the redirection header. The frontend_configure is a bit too early, I think, because then I would have to manually check if the URL isn't pointing at /archives or something. Using genpage, I just check for 404 and for the / at the end of the URL.

So here it is ... my very first plugin: DirectoryIndex

Posted: Tue Jul 11, 2006 12:54 pm
by garvinhicking
Hi!

That sounds good!

However, did you think about editing your .htaccess file and altering it from

"DirectoryIndex /index.php"

to

"DirectoryIndex index.php /index.php"

?

Best regards,
Garvin

Posted: Tue Jul 11, 2006 1:51 pm
by ghoti
I don't quite understand what that would do. The point of the plugin is to be able to use URLs that end in a /, which are then replaced with /index.html. So if I link to mysite.com/something/, that gets redirected to mysite.com/something/index.html, which happens to be a static page URL. This only happens if a 404 occurs, so mysite.com/blog/archives/ is not affected, for example. Maybe I just don't see the wood for all the trees, but it was simple enough to do this (with significant help from you ;).

Posted: Tue Jul 11, 2006 1:54 pm
by garvinhicking
Hi!

Aaah, now I understand that. I'm sorry, I was thinking those "index.html" files were really existing. :)

Best regards,
Garvin

Posted: Tue Jul 11, 2006 1:59 pm
by ghoti
Wow, you're fast! ;) No, this is all purely virtual. It's just because I have an existing site that I'm migrating, and I want to keep the existing URLs active. I also have some directories with stuff that get a .htaccess to protect them from s9y, so I know how to use that. Thanks again for the help!

Re: staticpages and index.html

Posted: Thu Jul 13, 2006 5:12 am
by blaire576
garvinhicking wrote:Hi!

The ".html" is required to match the rewriteRules. Using a wildcard "/" regexp would then match too many URLs, so a restriction to ".html" is actually required and I don't see a good way to work around that.

BTW, if s9y serves such pages, you'll notice that it throws a HTTP 404 error. But in the past people enjoyed the fact that instead of an empty 404 page the user sees the blog page.

You can use a plugin to handle such 404 requests! Look at the index.php file and search for "404". It calls the genpage.inc.php file, which executes a plugin hook, and there you can catch a 404 by either using the new $serendipity['view'] = 404 variable (1.0beta"4" or 1.1-alpha nightlies) or by looking at the various $serendipity['GET'] variables if they're set (Because genpage is also called for "valid" pages).

HTH,
Garvin
thanks for the tip garvin :roll: