Clean URLs

Please post answers on the most frequently asked questions about CMSimple
cmb
Posts: 14227
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Wed Jun 26, 2013 2:25 pm

Hi Maxim,
Maxim wrote:Created collection "CMSimple_XH_157_CleanURLs" and update "Update_CMSimple_XH_157_CleanURLs"
http://maxim.zp.ua/users/2/files.html
That's a nice service for the community; thank you. :)

I tried the full version; after switching to "ru", I was not able to call the site. The problem is in cmsimple/languages/ru.php line 182:

Code: Select all

$tx['urichar']['org']="А,Б,В,Г,Д,Е,Ё,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ы,Э,Ю,Я,а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ы,э,ю,я, &, –,Ъ,Ь,ъ,ь,",(,)";
As the syntax highlighting has indicated, the quote character (") is not properly escaped with a backslash. It should be:

Code: Select all

$tx['urichar']['org']="А,Б,В,Г,Д,Е,Ё,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ы,Э,Ю,Я,а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ы,э,ю,я, &, –,Ъ,Ь,ъ,ь,\",(,)";
One always has to be very careful when editing config and language files manually; there are at least 3 characters that has to be escaped with a backslash in the strings: the quote character (" -> \"), the dollar sign ($ -> \$) and the backslash itself (\ -> \\). This is not necessary when editing the files via the administration of CMSimple_XH (hopefully the last bugs regarding missing escaping when editing this way should have been fixed with CMSimple_XH 1.5.6).
Maxim wrote:Please tell me how to create CleanURLs to "Sitemap", "Print view", "Mailform", "Login".
Failed to Russify.
I have totally overlooked this issue in my clean URL solution. Having clean links for sitemap and mailform is easy. In cmsimple/cms.php around line 733 there is function ml(). This has to be changed:

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;
}
Localization (e.g. Russification) of the links is somewhat harder, as modifications are required in several places (it may be considered to do that for standard CMSimple_XH 1.5.8/1.6):
  • Function ml() has to be modified further:

    Code: Select all

    function ml($i) {
        global $f, $sn, $tx;
        $t = '';
        if ($f != $i)
            $t .= '<a href="' . $sn . '?' . uenc($tx['menu'][$i]) . '">';
        $t .= $tx['menu'][$i];
        if ($f != $i)
            $t .= '</a>';
        return $t;
    }
    This produces the desired links for sitemap and mailform.
  • To produce a localized login link, in cmsimple/login.php function lilink() has to be modified:

    Code: Select all

    function lilink() {
        global $cf, $adm, $sn, $u, $s, $tx;
        if (!$adm) {
            if ($cf['security']['type'] == 'javascript')
                return '<form id="login" action="' . $sn . '" method="post"><div id="loginlink">' . tag('input type="hidden" name="login" value="true"') . tag('input type="hidden" name="selected" value="' . $u[$s] . '"') . tag('input type="hidden" name="passwd" id="passwd" value=""') . '</div></form><a href="#" onclick="login(); return false">' . $tx['menu']['login'] . '</a>';
            else
                return a($s > -1 ? $s : 0, uenc($tx['menu']['login'])) . $tx['menu']['login'] . '</a>';
        }
    }
  • To produce a localized print link, function printlink() in cmsimple/cms.php has to be modified:

    Code: Select all

    function printlink() {
        global $f, $search, $file, $sn, $tx;
        $t = '&' . uenc($tx['menu']['print']);
        if ($f == 'search')
            $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
        else if ($f == 'file')
            $t .= '&file=' . $file;
        else if ($f != '' && $f != 'save')
            $t .= '&' . $f;
        else if (sv('QUERY_STRING') != '')
            $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
        return '<a href="' . $sn . '?' . $t . '">' . $tx['menu']['print'] . '</a>';
    }
  • To recognize the incoming URLs, one has to add in cmsimple/cms.php after line 221:

    Code: Select all

    $su = substr($su, 0, $cf['uri']['length']); // this line is line 221, which is already there
    
    foreach (array('login', 'mailform', 'print', 'sitemap') as $i) {
        if (!empty($GLOBALS[uenc($tx['menu'][$i])])) {
            $$i = 'true';
        }
    } 
Maxim wrote:How to add ".html"?
  • Function a() in cmsimple/cms.php around line 720 has to be further modified:

    Code: Select all

    function a($i, $x) {
        global $sn, $u, $cf, $adm;
        if ($i == 0 && !$adm) {
            if ($x == '' && $cf['locator']['show_homepage'] == 'true') {
                return '<a href="' . $sn . $u[0] . '">';
            }
        }
        return isset($u[$i]) ? '<a href="' . $sn . $u[$i] . '.html' . (!empty($x) ? '?' . $x : '') . '">' : '<a href="' . $sn . '.html' . (!empty($x) ? '?' . $x : '') . '">';
    } 
  • Function ml() in cmsimple/cms.php has to be further modified to cater for sitemap and mailform links:

    Code: Select all

    function ml($i) {
        global $f, $sn, $tx;
        $t = '';
        if ($f != $i)
            $t .= '<a href="' . $sn . '?' . uenc($tx['menu'][$i]) . '.html">';
        $t .= $tx['menu'][$i];
        if ($f != $i)
            $t .= '</a>';
        return $t;
    }
  • .htaccess has to be modified to accept these incoming URLs:

    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}/)?([^.]*)(.html)?$ $1?$2 [QSA]
I have noticed some issues with the appended .html, however. Somehow the mailform and sitemap links didn't work anymore. :? And the .html is not appended for the print link. Fixing this doesn't seem easy. I suggest to waive the .html.

Christoph
Last edited by cmb on Wed Jun 26, 2013 3:42 pm, edited 1 time in total.
Reason: added localization for print and login link; remarked problems with the .html ending
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: Clean URLs

Post by Maxim » Thu Jun 27, 2013 4:21 am

[ external image ] Здравствуйте.
The problem is in cmsimple/languages/ru.php line 182
Я так и подумал, но поздно, уже задал вопрос на форуме и был не за компьютером.
the quote character (" -> \"), the dollar sign ($ -> \$) and the backslash itself (\ -> \\)
В принципе знаю.
Fixing this doesn't seem easy.
Но возможно?

[ external image ] Hello.
The problem is in cmsimple/languages/ru.php line 182
I thought so, but too late already asked a question on the forum and was not at the computer.
the quote character (" -> \"), the dollar sign ($ -> \$) and the backslash itself (\ -> \\)
Know.
Fixing this doesn't seem easy.
But perhaps?
Last edited by Maxim on Tue Feb 04, 2014 6:10 am, edited 1 time in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

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

Re: Clean URLs

Post by Maxim » Thu Jun 27, 2013 8:12 am

[ external image ] Создал сбору "CMSimple_XH_157_CleanURLs" и обновление "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

cms.php
Удалил "?"

Code: Select all

function ml($i) {
    global $f, $sn, $tx;
    $t = '';
    if ($f != $i)
        $t .= '<a href="' . $sn . '' . uenc($tx['menu'][$i]) . '.html">';
    $t .= $tx['menu'][$i];
    if ($f != $i)
        $t .= '</a>';
    return $t;
}
Print view
cms.php
Удалил "?"
Добавил ".html"

Как заменить "&" на "_"?

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&' . uenc($tx['menu']['print']);
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
    return '<a href="' . $sn . '' . $t . '.html">' . $tx['menu']['print'] . '</a>';
}
Login
Как заменить?
/Welcome_to_CMSimple_XH.html?Login
на
Login.html

Когда возвращаюсь на главную страницу "/Welcome_to_CMSimple_XH" а хотелось бы "/"

[ external image ] Created collection "CMSimple_XH_157_CleanURLs" and update "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

cms.php
Deleted "?"

Code: Select all

function ml($i) {
    global $f, $sn, $tx;
    $t = '';
    if ($f != $i)
        $t .= '<a href="' . $sn . '' . uenc($tx['menu'][$i]) . '.html">';
    $t .= $tx['menu'][$i];
    if ($f != $i)
        $t .= '</a>';
    return $t;
}
Print view
cms.php
Deleted "?"
Added ".html"

How to replace the "&" to "_"?

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&' . uenc($tx['menu']['print']);
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
    return '<a href="' . $sn . '' . $t . '.html">' . $tx['menu']['print'] . '</a>';
}
Login
How to replace?
/Welcome_to_CMSimple_XH.html?Login
on
Login.html

When I go back to the main page "/Welcome_to_CMSimple_XH" and would be "/"
Last edited by Maxim on Wed Jan 20, 2016 6:30 am, edited 2 times in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

cmb
Posts: 14227
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Thu Jun 27, 2013 7:13 pm

Maxim wrote:
cmb wrote:Fixing this doesn't seem easy.
But perhaps?
It seems that is already fixed in your version. :)
Maxim wrote:When I go back to the main page "/Welcome_to_CMSimple_XH" and would be "/"
That seems to be a reasonable improvement even with the "normal" URLs. For "normal" URLs one could use:

Code: Select all

function a($i, $x) {
    global $sn, $u, $cf, $adm;
    if ($i == 0 && !$adm) {
        $url = $sn . ($x != '' ? '?' . $x : '');
    } elseif (isset($u[$i])) {
        $url = $sn . '?' . $u[$i] . $x;
    } else {
        $url = $sn . '?' . $x;
    }
    return '<a href="' . $url . '">';
}
For clean URLs:

Code: Select all

function a($i, $x) {
    global $sn, $u, $cf, $adm;
    $x = $x != '' ? '?' . $x : '';
    if ($i == 0 && !$adm) {
        $url = $sn . $x;
    } elseif (isset($u[$i])) {
        $url = $sn . $u[$i] . $x;
    } else {
        $url = $sn . $x;
    }
    return '<a href="' . $url . '">';
}
Both variants have a small drawback, though. When one logs in from the start page, the admin mode does not show the start page in edit mode, but "No page selected". That's caused by the "unreliable setting of $s".
Maxim wrote:How to replace?
/Welcome_to_CMSimple_XH.html?Login
on
Login.html
This is possible, but the link will be the same for all pages:

Code: Select all

function lilink() {
    global $cf, $adm, $sn, $u, $s, $tx;
    if (!$adm) {
        if ($cf['security']['type'] == 'javascript')
            return '<form id="login" action="' . $sn . '" method="post"><div id="loginlink">' . tag('input type="hidden" name="login" value="true"') . tag('input type="hidden" name="selected" value="' . $u[$s] . '"') . tag('input type="hidden" name="passwd" id="passwd" value=""') . '</div></form><a href="#" onclick="login(); return false">' . $tx['menu']['login'] . '</a>';
        else
            return '<a href="' . $sn . uenc($tx['menu']['login']) . '.html">' . $tx['menu']['login'] . '</a>';
    }
} 
Maxim wrote:Print view
[...]
How to replace the "&" to "_"?
You want something like "Welcome_to_CMSimple_XH_Print_view.html". However, I'm not sure if that's a good idea, as it disguises the relation to "Welcome_to_CMSimple_XH.html" somewhat. IMO "Welcome_to_CMSimple_XH.html?Print_view" is fine for humans as well as search engines.

Furthermore there is a technical issue. As the change had to be made in .htaccess via a RewriteRule, changing the localization doesn't work out of the box, and one would have to modify .htaccess accordingly.

And actually the print view is not working at all as it's now--it always shows the start page. That's not easy to solve. I suggested sticking with the "Print_view" as query parameter for now.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: Clean URLs

Post by Maxim » Thu Jun 27, 2013 9:20 pm

[ external image ] Создал сбору "CMSimple_XH_157_CleanURLs" и обновление "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Может зделать версию для печати в новом окне?
Может заменить "_" на "-" так красивее. "/Menu-Levels-and-Headings/Menu-Level-2-Page-1.html"
Может заменить "&" на "_". "/Menu-Levels-and-Headings/Menu-Level-2-Page-1_Print-view.html"
Добавил ".html" переход на главную страницу не получается. "/.html" "...404 Not Found..."

Code: Select all

function a($i, $x) {
    global $sn, $u, $cf, $adm;
    $x = $x != '' ? '?' . $x : '';
    if ($i == 0 && !$adm) {
        $url = $sn . $x;
    } elseif (isset($u[$i])) {
        $url = $sn . $u[$i] . $x;
    } else {
        $url = $sn . $x;
    }
    return '<a href="' . $url . '.html">';
}
При входе "/Login.html" выдаёт ошибку - "No page selected" "/?"

[ external image ] Created collection "CMSimple_XH_157_CleanURLs" and update "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Maybe make the print version in a new window?
Maybe replace the "_" to "-" so beautiful. "/Menu-Levels-and-Headings/Menu-Level-2-Page-1.html"
Maybe replace the "&" to "_". "/Menu-Levels-and-Headings/Menu-Level-2-Page-1_Print-view.html"
Added ".html" the transition to the main page does not work. "/.html" "...404 Not Found..."

Code: Select all

function a($i, $x) {
    global $sn, $u, $cf, $adm;
    $x = $x != '' ? '?' . $x : '';
    if ($i == 0 && !$adm) {
        $url = $sn . $x;
    } elseif (isset($u[$i])) {
        $url = $sn . $u[$i] . $x;
    } else {
        $url = $sn . $x;
    }
    return '<a href="' . $url . '.html">';
}
When you login "/Login.html" an error - "No page selected" "/?"
Last edited by Maxim on Wed Jan 20, 2016 6:30 am, edited 2 times in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

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

Вернул предыдущую копию.

Post by Maxim » Sat Jun 29, 2013 8:35 pm

[ external image ] Здравствуйте.
Вернул предыдущую копию, не очень красиво, но нет ошибок.

[ external image ] Hello.
Returned the previous copy, not very beautiful, but no errors.
Last edited by Maxim on Tue Feb 04, 2014 6:14 am, edited 1 time in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

cmb
Posts: 14227
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Sun Jun 30, 2013 11:02 am

Maxim wrote:Maybe make the print version in a new window?
We had a discussion about this not too long ago in this forum. There were some good arguments against it being made. Unfortunately I am not able to find the thread.

Anyway, it's easy to accomplish. In cmsimple/cms.php search for the following (around line 412):

Code: Select all

if ($print) {
    if ($cf['xhtml']['endtags'] == 'true') {
and replace it with:

Code: Select all

if ($print) {
    $onload .= 'window.print()';
    if ($cf['xhtml']['endtags'] == 'true') {
Maxim wrote:Maybe replace the "_" to "-" so beautiful. "/Menu-Levels-and-Headings/Menu-Level-2-Page-1.html"
Replace function uenc() in cmsimple/cms.php with the following:

Code: Select all

function uenc($s) {
    global $tx;
    if (isset($tx['urichar']['org']) && isset($tx['urichar']['new']))
        $s = str_replace(explode(",", $tx['urichar']['org']), explode(",", $tx['urichar']['new']), $s);
    return str_replace('+', '-', urlencode($s)); // here the space is replaced
}
Maxim wrote:Maybe replace the "&" to "_". "/Menu-Levels-and-Headings/Menu-Level-2-Page-1_Print-view.html"
Unfortunately that is not so easy, as I said. It's probably the best to leave it as it is, for now.
Maxim wrote:Added ".html" the transition to the main page does not work. "/.html" "...404 Not Found..."
It doesn't seem to possible to rewrite /.html at all. That is probably related to .html is treated as a hidden file by Apache (similar to .htaccess) and these file can't be accessed. I don't know if there's any way to change this.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: Clean URLs

Post by Maxim » Sun Jun 30, 2013 2:00 pm

[ external image ] Здравствуйте.
Создал сбору "CMSimple_XH_157_CleanURLs" и обновление "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

Я не об этом:

Code: Select all

if ($print) {
    $onload .= 'window.print()';
    if ($cf['xhtml']['endtags'] == 'true') {
А об этом:

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&' . uenc($tx['menu']['print']);
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
    return '<a href="' . $sn . '' . $t . '.html" target="_blank">' . $tx['menu']['print'] . '</a>';
}
Спасибо.

[ external image ] Hello.
Created collection "CMSimple_XH_157_CleanURLs" and update "Update_CMSimple_XH_157_CleanURLs"
http://foxpro.maxim.zp.ua/saytostroenie ... -urls.html

I'm not about this:

Code: Select all

if ($print) {
    $onload .= 'window.print()';
    if ($cf['xhtml']['endtags'] == 'true') {
About this:

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&' . uenc($tx['menu']['print']);
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
    return '<a href="' . $sn . '' . $t . '.html" target="_blank">' . $tx['menu']['print'] . '</a>';
}
Thank you.
Last edited by Maxim on Wed Jan 20, 2016 6:31 am, edited 2 times in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

cmb
Posts: 14227
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Clean URLs

Post by cmb » Sun Jun 30, 2013 2:25 pm

Maxim wrote:Создал сбору "CMSimple_XH_157_CleanURLs" и обновление "Update_CMSimple_XH_157_CleanURLs"
http://maxim.zp.ua/users/2/files.html
There are no files in the archive. :?
Maxim wrote:А об этом:
I assume the most one can have is something like this:

Code: Select all

function printlink() {
    global $f, $search, $file, $sn, $tx;
    $t = '&' . uenc($tx['menu']['print']);
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, "UTF-8") . $t;
    $url = $sn . $t . '.html';
    return '<a href="' . $url . '" onclick="var wnd=window.open(\'' . $url . '\'); wnd.print(); return false">' . $tx['menu']['print'] . '</a>';
}
But note, that the print view always shows the start page; see the last paragraph of http://cmsimpleforum.com/viewtopic.php? ... =20#p35993.
Christoph M. Becker – Plugins for CMSimple_XH

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

target="_blank" понравился больше

Post by Maxim » Sun Jun 30, 2013 8:18 pm

There are no files in the archive
[ external image ] Сделал исправления, разместил архив на сайте, ответил на форуме, проверил архив, оказалось, что это старая копия, удалил, проверил, снова разместил.
I assume the most one can have is something like this
Я экспериментировал с window.open но почему то target="_blank" понравился больше.
There are no files in the archive
[ external image ] Did fixes, posted archive on the website, answered on the forum, checked archive, it turned out that this is an old copy, deleted, checked, again posted.
I assume the most one can have is something like this
I experimented with window.open but for some reason target="_blank" liked more.
Last edited by Maxim on Tue Feb 04, 2014 6:16 am, edited 1 time in total.
Simple Hosting
Бедная, бросаемая бурею, безутешная!

Post Reply