Fall back / friendly url

Xagone

Situation : a webhosting as some security that prevent to run selfmade php, so when WB makes a new page / news, the page come out blank

My Solution : having a fallback position and not allowing WB to make files!

Note: all thoses mods have been made in WB 2.8.1 rev .1308

To create a fallback system we need htaccess, in that htaccess you add your fallback code like this :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

what it does, it's rewriting the internal url persive by apache if the url asked is not a file or folder (also catches 404 pages)

now I need to mod index.php
so, in the index, just after this code :
// Check if the config file has been set-up
if(!defined('WB_PATH')) {
header("Location: install/index.php");
exit(0);
}

i've install this code :
/* if the get var _route_ is active, then this is a fallback
meaning the physical page do not exists */
if(isset($_GET['_route_'])) {
if(!is_numeric($_GET['_route_'])) {
/* takes the url provided as something like /pages/my-page-name.php
and change it to what this page would have as "link" = /my-page-name */
$route = mysql_real_escape_string(str_replace(PAGES_DIRECTORY,'','/'.str_replace(PAGE_EXTENSION,'',$_GET['_route_'])));

/* this mysql query ask for the link as page or news ONLY */
$demande ='SELECT '.TABLE_PREFIX.'pages.page_id,'.TABLE_PREFIX.'mod_news_posts.section_id, '.TABLE_PREFIX.'mod_news_posts.post_id
FROM '.TABLE_PREFIX.'pages LEFT JOIN '.TABLE_PREFIX.'mod_news_posts
ON '.TABLE_PREFIX.'pages.page_id = '.TABLE_PREFIX.'mod_news_posts.page_id
WHERE '.TABLE_PREFIX.'pages.link LIKE \''.$route.'\' OR '.TABLE_PREFIX.'mod_news_posts.link LIKE \''.$route.'\'';

$dbcall = $database->query($demande);
if($rep = $dbcall->fetchRow()) {
$page_id = $rep['page_id'];
// if post_id is not null, than it's a news page, and I populate necessary vars
if($rep['post_id'] != 'NULL') {
$post_id = $rep['post_id'];
$section_id = $rep['section_id'];
}
} else {
/* this is a 404 page */
header('HTTP/1.1 404 NOT FOUND');
/* even if your principal page is shown, the server will give a 404 header
so metacrawler like Google will know this page does not exists
if you got a pre-arranged 404 page you could :
makes a header redirect here :
header('Location: my404page.html');
or if it's a WB page, link to the page number like : */
// $page_id = 1;
}
} else {
/* in this section the _route_ var is populated in numeric for,
meaning the page was call by number like this index.php?_route_=10 */
$page_id = $_GET['_route_'];
}
}


this is working as a fallback for normal pages, and news, i'll continue later to make WB continue without error if pages are not written.

But before I continue let me state the pros and cons of this (and why it should be in the dev) :

Pros :
- Pages folder is irrelevent, you can now do what you want with it
- Pages extensions also are irrelevent, you can make any extension you want or get rid of it alltogether.
- Make for more SEO friendly url possible
- Works on IIS if the server is using ISAPI_Rewrite (the httpd.ini part is almost identical as htaccess)
- Properly sends 404 header code so metacrawlers do not bother coming back to this page.

Cons :
- Works only with systems pages and news post, some modules using physical files will not works
Xagone Inc. (formerly VotreEspace)
[url="http://xagone.com/"]http://xagone.com/[/url]