MinigalNano
MinigalNano copied to clipboard
URL rewriting
Hello,
For best SEO and beautiful link I made some url rewriting with .htaccess and it's working perfectly when manually writing the modify URL in the address bar.
Now I need to modify the MinigalNano main code to generate folders links with the modified links structure. I really try a lot for one week now, and I can't found the solution but impossible to found the solution. Can Someone help me?
here are the link structure of MinigalNano : http://localhost:8888/photos.php?dir=land%2Fabstract%2Ftest
what I want : http://localhost:8888/photos/land/abstract/test/
the URL rewriting rules (working) :
# REWRITE PHOTOS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photos/(.*)/$ /photos.php?dir=$1 [L]
RewriteRule ^photos/(.*)/(.*)/(.*)/$ /photos.php?dir=$1%2F$1%2F$3 [L]
the PHP code of Minigal that generate folder link to modify :
//-----------------------
// READ FILES AND FOLDERS
//-----------------------
$files = array();
$dirs = array();
$img_captions = array();
if (is_dir($currentdir) && $handle = opendir($currentdir)) {
// LOAD CAPTIONS
while (false !== ($file = readdir($handle))) {
// LOAD FOLDERS
if (is_dir($currentdir . "/" . $file)) {
if ($file != "." && $file != "..") {
// FIRST IMAGE BG
unset($firstimage);
$firstimage = getfirstImage("$currentdir/" . $file);
$linkParams = http_build_query(
array('dir' => ltrim("$requestedDir/$file", '/')),
'',
'&'
);
$linkUrl = "$autogal_page_name?$linkParams";
$imgParams = http_build_query(
array(
'filename' => "$thumbdir/$file/$firstimage",
'size' => $thumb_size),
'',
'&'
);
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
$dirs[] = array(
"name" => $file,
"date" => filemtime($currentdir . "/" . $file),
"html" => "<div class=\"thumbs\"><a href=\"{$linkUrl}\"><div class=\"caption\"><div class=\"flowtype_gallery\"><h1>" . $file . "</h1></div><div class=\"caption_overlay\"></div></div><img src=\"{$imgUrl}\" alt='$label_loading' /></a></div>",
);
}
}
// LOAD FILES
if ($file != "." && $file != "..") {
if (preg_match("/.jpg$/i", $file)) {
//Read EXIF
$exifReaden = readEXIF($currentdir . "/" . $file);
$img_captions[$file] = $file . $exifReaden;
//Link
$linkUrl = str_replace('%2F', '/', rawurlencode("$currentdir/$file"));
$imgParams = http_build_query(
array(
'filename' => "$thumbdir/$file",
'size' => $thumb_size),
'',
'&'
);
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
$files[] = array(
"name" => $file,
"date" => filemtime($currentdir . "/" . $file),
"size" => filesize($currentdir . "/" . $file),
"html" => "<div class=\"thumbs\"><a href=\"{$linkUrl}\"><div class=\"caption\"><div class=\"flowtype_gallery\"><h1><i class=\"ion-ios-plus-empty\"></i></h1></div><div class=\"caption_overlay\"></div></div><img class=\"lazyload\" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src=\"$imgUrl\" alt=\"$label_loading\" title=\"" . htmlentities($img_captions[$file]) . "\" /></a></div>");
}
}
}
closedir($handle);
} else {
die("ERROR: Could not open " . htmlspecialchars(stripslashes($currentdir)) . " for reading!");
}
Thank you so much
Jim
Yep, could be very nice to have in miniGal, thanks for the url rewriting stuff ! We should set a condition : if modrewrite is activated, before modifying the links I guess.
Will be implemented after the refactor as an option :)