redirect pages with trailing slash

This commit is contained in:
Diego Najar 2018-08-27 22:19:42 +02:00
parent 186ee576e7
commit 9676e995ef
9 changed files with 23 additions and 16 deletions

View File

@ -241,7 +241,7 @@ EOF;
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$disabled = isset($args['disabled'])?'disabled':''; $disabled = empty($args['disabled'])?'':'disabled';
$class = 'form-control'; $class = 'form-control';
if (isset($args['class'])) { if (isset($args['class'])) {

View File

@ -208,8 +208,6 @@
'tip'=>$L->g('Write a template name to filter the page in the theme and change the style of the page.') 'tip'=>$L->g('Write a template name to filter the page in the theme and change the style of the page.')
)); ));
echo Bootstrap::formTitle(array('title'=>'SEO'));
// Tags // Tags
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'tags', 'name'=>'tags',
@ -219,6 +217,8 @@
'tip'=>$L->g('Write the tags separated by comma') 'tip'=>$L->g('Write the tags separated by comma')
)); ));
echo Bootstrap::formTitle(array('title'=>'SEO'));
// Friendly URL // Friendly URL
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'slug', 'name'=>'slug',

View File

@ -212,7 +212,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g('Settings'), 'icon'=>'cog'));
'class'=>'', 'class'=>'',
'placeholder'=>'', 'placeholder'=>'',
'tip'=>DOMAIN.$site->uriFilters('blog'), 'tip'=>DOMAIN.$site->uriFilters('blog'),
'disabled'=>!$site->uriFilters('blog') 'disabled'=>Text::isEmpty($site->uriFilters('blog'))
)); ));
echo ' echo '

View File

@ -58,6 +58,13 @@ if ($site->homepage() && $url->whereAmI()==='home') {
// Build specific page // Build specific page
if ($url->whereAmI()==='page') { if ($url->whereAmI()==='page') {
// Check if the URL has trailing slash
$pageKey = $url->slug();
if (Text::endsWith($pageKey, '/')) {
$pageKey = rtrim($pageKey, '/');
Redirect::url(DOMAIN_PAGES.$pageKey);
}
$content[0] = $page = buildThePage(); $content[0] = $page = buildThePage();
} }
// Build content by tag // Build content by tag

View File

@ -2,10 +2,10 @@
class Redirect { class Redirect {
public static function url($url) public static function url($url, $httpCode=301)
{ {
if (!headers_sent()) { if (!headers_sent()) {
header("Location:".$url, TRUE, 302); header("Location:".$url, TRUE, $httpCode);
exit; exit;
} }

View File

@ -96,9 +96,8 @@ class Text {
public static function endsWith($string, $endsString) public static function endsWith($string, $endsString)
{ {
$length = (-1)*self::length($endsString); //$length = (-1)*self::length($endsString);
return (mb_substr($string, -1)===$endsString);
return( mb_substr($string, $length)===$endsString );
} }
public static function endsWithNumeric($string) public static function endsWithNumeric($string)

View File

@ -647,6 +647,7 @@ class Pages extends dbJSON {
public function generateKey($text, $parent=false, $returnSlug=false, $oldKey='') public function generateKey($text, $parent=false, $returnSlug=false, $oldKey='')
{ {
global $L; global $L;
global $site;
if (Text::isEmpty($text)) { if (Text::isEmpty($text)) {
$text = $L->g('empty'); $text = $L->g('empty');

View File

@ -306,6 +306,7 @@ function install($adminPassword, $timezone)
$dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL; $dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL;
$data = array(); $data = array();
$slugs = array();
foreach ($pagesToInstall as $page) { foreach ($pagesToInstall as $page) {
$slug = $page; $slug = $page;
@ -324,7 +325,7 @@ function install($adminPassword, $timezone)
'position'=>1, 'position'=>1,
'coverImage'=>'', 'coverImage'=>'',
'md5file'=>'', 'md5file'=>'',
'category'=>'', 'category'=>'general',
'uuid'=>md5(uniqid()), 'uuid'=>md5(uniqid()),
'parent'=>'', 'parent'=>'',
'template'=>'', 'template'=>'',
@ -333,6 +334,8 @@ function install($adminPassword, $timezone)
'noarchive'=>false 'noarchive'=>false
); );
array_push($slugs, $slug);
file_put_contents(PATH_PAGES.$L->get($slug).DS.FILENAME, $L->get($content), LOCK_EX); file_put_contents(PATH_PAGES.$L->get($slug).DS.FILENAME, $L->get($content), LOCK_EX);
} }
file_put_contents(PATH_DATABASES.'pages.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); file_put_contents(PATH_DATABASES.'pages.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
@ -438,7 +441,7 @@ function install($adminPassword, $timezone)
// File categories.php // File categories.php
$data = array( $data = array(
'general'=>array('name'=>'General', 'description'=>'', 'template'=>'', 'list'=>array()), 'general'=>array('name'=>'General', 'description'=>'', 'template'=>'', 'list'=>$slugs),
'music'=>array('name'=>'Music', 'description'=>'', 'template'=>'', 'list'=>array()), 'music'=>array('name'=>'Music', 'description'=>'', 'template'=>'', 'list'=>array()),
'videos'=>array('name'=>'Videos', 'description'=>'', 'template'=>'', 'list'=>array()) 'videos'=>array('name'=>'Videos', 'description'=>'', 'template'=>'', 'list'=>array())
); );

View File

@ -11,9 +11,6 @@ Things to do:
-- time for check user logged -- time for check user logged
-- thumbnails sizes and compression -- thumbnails sizes and compression
- Plugin Links
-- Update CSS for Bootstrap
- Plugin sitemap - Plugin sitemap
-- Update CSS for Bootstrap -- Update CSS for Bootstrap