Clean URLs

Please post answers on the most frequently asked questions about CMSimple
Post Reply
Maxim
Posts: 121
Joined: Thu Jun 13, 2013 6:52 am
Location: Запорожье
Contact:

Re: Clean URLs

Post by Maxim » Tue Sep 03, 2013 4:20 pm

[ external image ] Да, конечно.
cmsimple/config.php
cmsimple/defaultconfig.php
5-я строка

Code: Select all

$cf['site']['template']="photo11";

Code: Select all

<area shape="poly" coords="62,21,84,21,84,43,62,43,62,21" href="?sitemap" alt="">
<area shape="poly" coords="93,21,115,21,115,43,93,43,93,21" href="?mailform" alt="">
<area shape="poly" coords="32,21,54,21,54,43,32,43,32,21" href="index.php" alt="">
[ external image ] Yes, of course.
cmsimple/config.php
cmsimple/defaultconfig.php

Code: Select all

$cf['site']['template']="photo11";

Code: Select all

<area shape="poly" coords="62,21,84,21,84,43,62,43,62,21" href="?sitemap" alt="">
<area shape="poly" coords="93,21,115,21,115,43,93,43,93,21" href="?mailform" alt="">
<area shape="poly" coords="32,21,54,21,54,43,32,43,32,21" href="index.php" alt="">
Last edited by Maxim on Tue Feb 04, 2014 6:04 am, edited 1 time in total.

cmb
Posts: 13013
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Tue Sep 03, 2013 4:34 pm

I've seen that you're using:

Code: Select all

<area shape="poly" coords="62,21,84,21,84,43,62,43,62,21" <?php echo sitemaplink();?> >
    <area shape="poly" coords="93,21,115,21,115,43,93,43,93,21" <?php echo mailformlink();?> >
    <area shape="poly" coords="32,21,54,21,54,43,32,43,32,21" <?php echo a(0, ''), $tx['locator']['home'], '</a>';?> >
That doesn't work as expected, and results in the output you want to remove. You can read about imagemaps on http://www.w3schools.com/tags/tag_map.asp (I'm sure, there are Russian articles about imagemaps as well).

If you want to replace the imagemap in photo11 with text links, you have to replace line 43 in template.htm with something like:

Code: Select all

        <td colspan="2"><?php echo sitemaplink();?> <?php echo mailformlink();?> <?php echo a(0, ''), $tx['locator']['home'], '</a>';?> </td>
Christoph M. Becker –Plugins for CMSimple_XH

Maxim
Posts: 121
Joined: Thu Jun 13, 2013 6:52 am
Location: Запорожье
Contact:

Создал Addon, но "Версия для печати" не работает, поможете?

Post by Maxim » Sat Sep 07, 2013 5:24 am

[ external image ] Здравствуйте.
Создал Addon, но "Версия для печати" не работает, поможете?
Печать только главной страницы.
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Обновлял так:
CMSimple_XH_Upgrade_15_to_158
Addon-CMSimple_XH-158-CleanURLs-2013-09-05

Пример:
http://maxim.maxim.zp.ua/
http://ubuntu.maxim.zp.ua/
http://k510i.maxim.zp.ua/
http://foxpro.maxim.zp.ua/

[ external image ] Hello.
Created Addon, but "Print view" does not work, any help?
Print only the home page.
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Update:
CMSimple_XH_Upgrade_15_to_158
Addon-CMSimple_XH-158-CleanURLs-2013-09-05

Example:
http://maxim.maxim.zp.ua/
http://ubuntu.maxim.zp.ua/
http://k510i.maxim.zp.ua/
http://foxpro.maxim.zp.ua/

[ external image ] Guten Tag.
Erstellt Addon, aber die "Druckansicht" nicht funktioniert, helfen?
Drucken Sie nur die Startseite.
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Erfrischte so:
CMSimple_XH_Upgrade_15_to_158
Addon-CMSimple_XH-158-CleanURLs-2013-09-05

Beispiel:
http://maxim.maxim.zp.ua/
http://ubuntu.maxim.zp.ua/
http://k510i.maxim.zp.ua/
http://foxpro.maxim.zp.ua/
Last edited by Maxim on Wed Jan 20, 2016 6:24 am, edited 2 times in total.

Maxim
Posts: 121
Joined: Thu Jun 13, 2013 6:52 am
Location: Запорожье
Contact:

$t = '&amp;print';

Post by Maxim » Mon Sep 09, 2013 7:03 am

[ external image ] Не очень хороший способ решения:
cmsimple/cms.php

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&print';
    if ($f == 'search')
        $t .= '&function=search&search=' . XH_hsc(stsl($search));
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = XH_hsc(sv('QUERY_STRING')) . $t;
    return '<a href="' . $sn . '' . $t . '.html" target="_blank">' . $tx['menu']['print'] . '</a>';
}
[ external image ] Not a very good solution:
cmsimple/cms.php

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&print';
    if ($f == 'search')
        $t .= '&function=search&search=' . XH_hsc(stsl($search));
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = XH_hsc(sv('QUERY_STRING')) . $t;
    return '<a href="' . $sn . '' . $t . '.html" target="_blank">' . $tx['menu']['print'] . '</a>';
}
[ external image ] Nicht sehr gute Möglichkeit, die Lösung:
cmsimple/cms.php

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&print';
    if ($f == 'search')
        $t .= '&function=search&search=' . XH_hsc(stsl($search));
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = XH_hsc(sv('QUERY_STRING')) . $t;
    return '<a href="' . $sn . '' . $t . '.html" target="_blank">' . $tx['menu']['print'] . '</a>';
}
Last edited by Maxim on Tue Feb 04, 2014 6:05 am, edited 1 time in total.

cmb
Posts: 13013
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Mon Sep 09, 2013 11:55 am

Hi Maxim,
Maxim wrote:Created Addon, but "Print view" does not work, any help?
Print only the home page.
In cmsimple/cms.php replace line 235:

Code: Select all

$su == 0;
with:

Code: Select all

if ($i != 'print') $su = '';
Christoph
Christoph M. Becker –Plugins for CMSimple_XH


Maxim
Posts: 121
Joined: Thu Jun 13, 2013 6:52 am
Location: Запорожье
Contact:

Админка и версия для печати

Post by Maxim » Tue Sep 10, 2013 5:53 am

Last edited by Maxim on Tue Feb 04, 2014 6:06 am, edited 1 time in total.

tanavots
Posts: 69
Joined: Sat Feb 25, 2012 4:18 pm

Re: Clean URLs

Post by tanavots » Sun Jan 05, 2014 11:59 am

As CMSimple 1.6 have lot of changes, how about modifying it to use Clean URLs. Can someone give directions?

Best,
A

cmb
Posts: 13013
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Wed Jan 08, 2014 1:43 pm

tanavots wrote:Can someone give directions?
I'll try to assemble the instructions today.
Christoph M. Becker –Plugins for CMSimple_XH

cmb
Posts: 13013
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Thu Jan 09, 2014 3:44 pm

Hello Community,

the following is a recipe to have clean URLs with CMSimple_XH 1.6. Note, that plugins might still produce "classic" URLs.

Requirements
You need an Apache server with mod_rewrite enabled, and need to be confident editing source code files (see http://www.cmsimple-xh.org/wiki/doku.ph ... es_offline).

Prepare your site to have almost clean URLs
At first change the configuration setting of Uri -> Seperator to "/". Then have a look at your page URLs. If the page headings contain special characters, you have to get rid of them; see http://www.cmsimple-xh.org/wiki/doku.ph ... n_headings.

I recommend this step anyway, even if you're not interested in clean URLs, as it makes the URLs better readable and exchangeable, and is necessary to make deep links from some platform (such as Facebook) working.

Add the necessary rewrite rules for the webserver
Add a file .htaccess in the root folder of the CMSimple installation (right beside the main index.php). Insert the following:

Code: Select all

RewriteEngine on

# Do not rewrite requests to existing directories and files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Everything else is a CMSimple_XH page request,
# so shift the subfolders to the beginning of the query string
RewriteRule ^([A-z]{2}/)?(.*)$ $1?$2 [QSA]
Modify CMSimple to cater for the clean URLs
  • Change $sn

    Find the following code in cmsimple/cms.php:

    Code: Select all

    $sn = preg_replace(
        '/([^\?]*)\?.*/', '$1',
        sv(($iis ? 'SCRIPT_NAME' : 'REQUEST_URI'))
    ); 
    and replace it with:

    Code: Select all

    $sn = preg_replace('/index\.php$/', '', $_SERVER['SCRIPT_NAME']); 
  • Change the links that CMSimple produces
    Find function a() in cmsimple/functions.php. Replace it with the following:

    Code: Select all

    function a($i, $x)
    {
        global $sn, $u, $cf;
    
        if ($i == 0 && !XH_ADM) {
            if ($x == '' && $cf['locator']['show_homepage'] == 'true') {
                return '<a href="' . $sn . $u[0] . '">';
            }
        }
        return isset($u[$i])
            ? '<a href="' . $sn . $u[$i] . (!empty($x) ? '?' . $x : '') . '">'
            : '<a href="' . $sn . (!empty($x) ? '?' . $x : '') . '">';
    } 
    Find function ml() in cmsimple/functions.php, and replace it with the following:

    Code: Select all

    function ml($i)
    {
        global $f, $sn, $tx;
    
        $t = '';
        if ($f != $i) {
            $t .= '<a href="' . $sn . $i . '">';
        }
        $t .= $tx['menu'][$i];
        if ($f != $i) {
            $t .= '</a>';
        }
        return $t;
    }
  • Add a "base" element
    Find function head() in cmsimple/tplfuncs.php. Add the following lines before the return statement:

    Code: Select all

        global $sn;
        $t .= tag('base href="' . CMSIMPLE_URL . '"') . PHP_EOL; 
Now the basic modifications are done and you can test your site. When you navigate around even in second languages everything should be alright and you already have clean URLs.

Duplicate Content
You might have already noticed, that the old URLs (those after switching to almost clean URLs) still work. That's basically no problem, but search engines don't like this duplicate content (i.e. the same page accessible via more than one URL). The solution is to insert a canonical link element. Please note, that ge_canonical doesn't cater for clean URLs.

So put the following to userfuncs.php:

Code: Select all

<?php

/**
 * Returns the canonical link tag. Works only for clean URLs.
 *
 * @global string  The absolute path to the directory of the folder which contains index.php.
 * @global string  The GET parameter of the current page.
 * @global array  The GET parameters of all pages.
 * @param  array $ignoreParams  The paramaters to ignore in the canonical URL (e.g. print).
 * @return string  The (X)HTML.
 */
function canonical($ignoreParams = array())
{
    global $sn, $su, $u;

    $params = array();
    $allParams = explode('&', $_SERVER['QUERY_STRING']);
    foreach ($allParams as $param) {
        $param = explode('=', $param);
        $key = $param[0];
        if ($key != $su && !in_array($key, $ignoreParams)) {
            $params[$key] = isset($param[1]) ? $param[1] : null;
        }
    }
    ksort($params);
    $newParams = array();
    foreach ($params as $key => $value) {
        $newParams[] = $key . (isset($value) ? "=$value" : '');
    }

    $baseURL = 'http'
        . (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : '')
        . '://' . $_SERVER['SERVER_NAME']
        . ($_SERVER['SERVER_PORT'] < 1024 ? '' : ':' . $_SERVER['SERVER_PORT'])
        . $sn;

    $canonicalSU = $su == $u[0] ? '' : $su;
    $url = $baseURL . $canonicalSU;
    if (!empty($newParams)) {
        $url .= '?' . (empty($canonicalSU) ? '&' : '')
            . implode('&', $newParams);
    }
    $link = tag('link rel="canonical" href="'
                . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . '"') . "\n";
    return $link;
}

/*
 * Insert the canonical link to the "head" element, when not in admin mode.
 */
if (!$adm) {
    $hjs .= canonical(array('logout', 'print'));
}

?>
Please note, that the argument to canonical() at the bottom of the code should be extended by further GET parameters, which should be ignored in the canonical link. Which one, depend on extensions you're using. E.g. for Calendar you might change the line to:

Code: Select all

    $hjs .= canonical(array('logout', 'month', 'print', 'year')); 
Missing stylesheet for the editor
When you log in to the back-end, you'll notice, that the template's stylesheet isn't used by the editor any more (tinyMCE and CKeditor)[1]. To change that for tinyMCE you have to extend your init file with the following:

Code: Select all

    document_base_url: "%BASE_URL%",
Toggling between edit and view mode in the back-end
Switching to view mode in the back-end will change to the "non clean" URLs. That's no problem, but you can change this behavior easily. Find function XH_adminMenu() in cmsimple/adminfuncs.php and replace the following line[2]:

Code: Select all

            'url' => '?' . $su . '&' . $changeMode,
with:

Code: Select all

            'url' => $su . '&' . $changeMode,
Enjoy,
Christoph

PS: [1] It is used for top level pages, however, but not for subpages.

PPS: [2] Since CMSimple_XH 1.6.2 the line is:

Code: Select all

            'url' => $sn . '?' . $su . '&' . $changeMode,
what has to be replaced with:

Code: Select all

            'url' => $sn . $su . '&' . $changeMode,
Last edited by cmb on Fri May 30, 2014 11:01 am, edited 4 times in total.
Reason: added PS; added changes for ml(); added PPS
Christoph M. Becker –Plugins for CMSimple_XH

Post Reply