If you want fancyurls, but don't want the extension-free files and forcetypes in your htacces, try this one.
Create a .htaccess file (or edit it) so that it contains this:
RewriteEngine On RewriteRule ^member/(.*) index.php?arr=member/$1 RewriteRule ^item/(.*) index.php?arr=item/$1 RewriteRule ^category/(.*) index.php?arr=category/$1 RewriteRule ^blog/(.*) index.php?arr=blog/$1 RewriteRule ^archive/(.*) index.php?arr=archive/$1 RewriteRule ^archives/(.*) index.php?arr=archives/$1
Now the fanyurl style will be translated in an array with all the params. Now just edit your index.php so that it rebuilds it to normal getvars ($_GET[“var”] = “value”;). Don't forget to change the $CONF['SELF'] line to the absolute url to your domain without ending slash!
<?php $requestvars = $_GET["arr"]; $request_arr = explode("/", $requestvars); if ($request_arr[0] == "item") { $_GET["itemid"] = $request_arr[1]; $firsti = 2; } elseif ($request_arr[0] == "member") { $_GET["memberid"] = $request_arr[1]; $firsti = 2; } elseif ($request_arr[0] == "category") { $_GET["catid"] = $request_arr[1]; $firsti = 2; } elseif ($request_arr[0] == "blog") { $_GET["blogid"] = $request_arr[1]; $firsti = 2; } elseif ($request_arr[0] == "archive") { $_GET["blogid"] = $request_arr[1]; $_GET["archive"] = $request_arr[2]; $firsti = 3; } elseif ($request_arr[0] == "archives") { $_GET["archivelist"] = $request_arr[1]; $firsti = 2; } $xflag = true; for ($i = $firsti; $i < count($request_arr); $i++) { if ($xflag == true) { $j = $i + 1; $_GET[$request_arr[$i]] = $request_arr[$j]; $xflag = false; } elseif ($xflag == false) { $xflag = true; } } // This file will generate and return the main page of the site $CONF = array(); $CONF['Self'] = 'http://www.example.com/blog'; include('./config.php'); selector(); ?>
For support just post something at the forum in my topic ;).
Have fun with it
, Legolas.
submitted by ketsugi
Another alternate FancyURL method using mod_rewrite is listed below. This method completely mimics the ForceType method using only mod_rewrite, thus allowing it to be extended further with NP_FancierURL for WordPress-like URLs.
Put this code in your .htaccess file:
RewriteRule ^member/(.*) /member.php/$1 RewriteRule ^item/(.*) /item.php/$1 RewriteRule ^blog/(.*) /blog.php/$1 RewriteRule ^archive/(.*) /archive.php/$1 RewriteRule ^archives/(.*) /archives.php/$1
Then rename all the FancyURL files (item, member, etc) by giving them .php extensions. Once this is done, follow the rest of the normal FancyURL directions.
See this forum post for more information.
(The list above is missing the rule for 'category' as well as the 'RewriteEngine On' line that needs to go at the top.)
submitted by kl0k
UPDATE:
I'm sorry, this doesn't work correctly because apache does not send $_GET, $_POST variables to 404 error pages. Nucleus send comments by $_POST.
It's not possible to send comments, vote karma and so on. (all what is sent by $_POST)
I'm realy sorry if you fall into some troubles by this way.
I'll try to fix it by action.php file and some little changes in form.
Stay tuned
On my site, where I'm (free) hosted is not allowed use .htacces file. I can't use ForceType or mod_rewrite in other meaning: it's not possible to use default implementation of FancyURL.
For my hosting it's allowed to use own 404 error page. The way how to do FancyURL redirection, is very simple: *Make own 404 script* On invalid request (valid FancyURL) you will get requested URL to your script. You can handle original URL, parse it, generate http header 200 OK and send to user browser requested valid page.
How to get it work?
Page 404 php code:
<?php
include('./fancyurls.config.php');
include('config.php');
$parsing = array(
$CONF['ItemKey'] => parse404_item,
$CONF['ArchiveKey'] => parse404_archive,
$CONF['MemberKey'] => parse404_member,
$CONF['ArchivesKey'] => parse404_archives,
$CONF['CategoryKey'] => parse404_category,
$CONF['BlogKey'] => parse404_blog,
);
$URI = $_SERVER['REQUEST_URI'];
$parts = explode("/",$URI);
$do404 = TRUE;
foreach($parts as $index => $part)
{
if(isset($parsing[$part]))
call_user_func($parsing[$part],$index,&$parts);
$do404 = FALSE;
}
}
if ($do404)
{
@header("HTTP/1.1 404 Not Found");
die("<html> <h1>Page Not Found</h1> URL You are requested Not Found </html>");
}
@header("HTTP/1.1 200 OK");
selector();
function parse404_item($index,$url_parts)
{
global $itemid;
$itemid = intval($url_parts[$index+1]);
}
function parse404_archive($index,$url_parts)
{
global $blogid, $archive;
$blogid = intval($url_parts[$index+1]);
$archive = $url_parts[$index+2];
}
function parse404_member($index,$url_parts)
{
global $memberid;
$memberid = intval($url_parts[$index+1]);
}
function parse404_archives($index,$url_parts)
{
global $archivelist;
$archivelist = intval($url_parts[$index+1]);
}
function parse404_category($index,$url_parts)
{
global $catid;
$catid = intval($url_parts[$index+1]);
}
function parse404_blog($index,$url_parts)
{
global $blogid;
$blogid = intval($url_parts[$index+1]);
}
?>