re: PLEASE give me CLEAN URLS!

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
kweku
Posts: 90
Joined: Sun Jan 18, 2009 3:37 pm

re: PLEASE give me CLEAN URLS!

Post by kweku » Mon Aug 06, 2012 1:46 pm

hi, im not sure if addons and plugins is the right area but i am hoping there is someone out there who can help.

there is a very outdated guide on using clean URLs for cmsimple ( removing the " ? '' query string from urls ) on the wiki - http://www.cmsimplewiki.com/doku.php/ti ... /clean_url

it would be really appreciated if the community could look at updating this guide to work with cmsimple xh, whether its a plugin or wiki update - anything would be good!

if a flat file cms like get simple can do it then cmsimple can - http://get-simple.info/start/cms-comparisons/

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

Re: re: PLEASE give me CLEAN URLS!

Post by cmb » Mon Aug 06, 2012 3:09 pm

Hi kweku,

I don't really understand, why everybody is still so hipped about the so-called "clean urls". I doubt that it makes a difference for users. Most users have no understanding of the structure of URLs, so in the rare case they have to enter a URL directly in the browser's address line, they will do it with or without the "?". The few who do understand the structure of URLs, might have some trouble to remember to put in the "?" in, but I guess, they'll get it on the second try. So what remains is SEO. But if I'm not mistaken, modern search engines have absolutely no trouble with query parameters. In fact they treat different query parameters as different URLs, so what's much more important for SEO, is to tell the search bots which query parameters to ignore. E.g. the SE will treat http://www.example.com/ and http://www.example.com/?&print as different pages, resulting in DC. The ge_canonical plugin caters for several cases, but IMO regarding several plugins a more general and tunable solution is needed.

Having said this, I'm not against the clean URLs. But there are several problems:
  • clean URLs require some URL rewriting mechanism (e.g. mod_rewrite for Apache), but this is not offered consistently by all hosting companies (not all use Apache). This is probably the reason, why CMSimple never made clean URLs the default: it's meant to run "everywhere" (AFAIK GetSimple on the contrary requires PHP 5.2 and an Apache server).
  • to use the URL rewriting, one has to specify some rules. So if a request to http://www.example.com/start is made, this should be rewritten to be http://www.example.com/?start. But wait: what if there is a folder named start/, that should be accessed by the given URL? This has to be specified as exception in the URL rewrite rules. But if the exception is specified, no page may be called "start" any more. (in practise this might be a minor problem, but it has to be considered nonetheless).
  • to present the clean URLs in the first place, the core of CMSimple has to be adapted in several places, and all plugins have to be adapted too. This wouldn't be necessary, if all plugin where using a() instead of constructing the URLs manually, but I'm afraid that's often not the case.
  • as the pages might be accessed with the "non-clean" URLs directly, a <link rel="canonical" ...> has to be inserted to the pages, to avoid DC
  • and finally the problems described at the end of section 4 of the cited wiki article
But, however, I'll have a closer look at the issue, and see, if I'm able to update the wiki article. Might take some time, though.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: re: PLEASE give me CLEAN URLS!

Post by cmb » Wed Aug 08, 2012 9:46 pm

I achieved some first somewhat promising results. In the following a fresh installation of CMSimple_XH 1.5.3 is assumed (including the default content), running under an Apache webserver. This is meant for demonstration and testing purposes only -- do not use in a production environment!
  1. add a new config option to cmsimple/config.php:

    Code: Select all

    $cf['uri']['base']="/" 
    If CMSimple_XH is installed in a subfolder subfolder/ of the web root, you have to write:

    Code: Select all

    $cf['uri']['base']="/subfolder/" 
  2. insert in cmsimple/cms.php before line 186:

    Code: Select all

    $sn = $cf['uri']['base']; 
  3. change cmsimple/cms.php line 656 to:

    Code: Select all

                return '<a href="' . $sn . $u[0] . '">'; 
    and line 659 to

    Code: Select all

        return isset($u[$i]) ? '<a href="' . $sn . $u[$i] . (!empty($x) ? '?' . $x : '') . '">' : '<a href="' . $sn . (!empty($x) ? '?' . $x : '') . '">'; 
  4. add a .htaccess in the CMSimple_XH root folder:

    Code: Select all

    RewriteEngine on
    # To prevent loop:
    RewriteCond %{REQUEST_URI}  !index.php
    # Do not rewrite requests to existing directories:
    RewriteCond %{REQUEST_URI}  !css
    RewriteCond %{REQUEST_URI}  !images
    RewriteCond %{REQUEST_URI}  !downloads
    RewriteCond %{REQUEST_URI}  !plugins
    RewriteCond %{REQUEST_URI}  !templates
    RewriteCond %{REQUEST_URI}  !userfiles
    # Do not rewrite requests with any query strings:
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^(.*)$ ./index.php?$1
  5. in cmsimple/cms.php after line 892 add:

    Code: Select all

        $t .= tag('base href="' . $cf['uri']['base'] . '"'); 
  6. in cmsimple/config.php change $cf['uri']['seperator']:

    Code: Select all

    $cf['uri']['seperator']="/"; 
  7. give it a try! Basically it should work, but you can't access any pages with special characters (e.g. "Templates & Plugins"). You have to avoid these characters, or make use of urichar_org/new. So change these in cmsimple/languages/en.php:

    Code: Select all

    $tx['urichar']['new']="and,";
    $tx['urichar']['org']="&, – "; 
  8. to have the URLs all lower case and with "-" instead of "_", change cmsimple/cms.php line 684:

    Code: Select all

        return str_replace('+', '-', strtolower(urlencode($s))); 
Remaining problems:
  • "Templates & Plugins" can't be called, as this is prohibited by the RewriteCond !templates. I'm quite sure, this can be solved, but I have to learn some more about mod_rewrite. If someone else has a solution at hand, please post it.
  • second languages don't work. Again something that might be resolved using more sofisticated rewrite rules.
  • The WYSIWYG editors won't get the stylesheet for pages not on toplevel (<h1>) as the <base> element is missing. This can perhaps be solved by some editor configuration.
  • The DC issue. This has to be solved by a <link rel="canonical"> element.
  • If one inserts a special character, that's not handled by urichar, to a page heading, the page can't be accessed anymore via the menu.
  • and probably some more (at least) minor issues
Any ideas, improvements, suggestions and comments are welcome. Even if I still think, that the clean URLs are not necessary, it might be nice, if one can have them, if he likes.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: re: PLEASE give me CLEAN URLS!

Post by cmb » Mon Aug 13, 2012 3:31 pm

I found out, that login is not possible at all with the current solution. So change the .htaccess to:

Code: Select all

RewriteEngine on
# To prevent loop:
RewriteCond %{REQUEST_URI}  !index.php
# Do not rewrite requests to existing directories and files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Do not rewrite requests with any query strings:
#RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ ./index.php?$1 [QSA]
This will solve the issue that "Templates & Plugins" can't be accessed too. And you don't have to specify each directory as RewriteCond anymore.

To make the stylesheet available to the editor, just insert into plugins/tinymce/inits/init_*.js above the first option:

Code: Select all

document_base_url: '/',
or in case you have CMSimple_XH installed in a subfolder of the web root:

Code: Select all

document_base_url: '/the_subfolder/',
Still remaining problems:
  • second languages don't work.
  • The DC issue. This has to be solved by a <link rel="canonical"> element.
  • If one inserts a special character, that's not handled by urichar, to a page heading, the page can't be accessed anymore via the menu.
  • and probably some more (at least) minor issues
I'll have a further look at the remaining issues, as soon as my time permits.
Christoph M. Becker – Plugins for CMSimple_XH

kweku
Posts: 90
Joined: Sun Jan 18, 2009 3:37 pm

Re: re: PLEASE give me CLEAN URLS!

Post by kweku » Tue Aug 14, 2012 10:11 am

im just a humble designer so i unfortunately cannot contribute but really appreciate the time you have given.

even if in the long term you find that the process is not 100% achievable', im sure it will be in the future.

i often go to http://www.opensourcecms.com/ to see what's out there and im glad contributers like yourself are helping to keep cmsimple fresh

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

Re: re: PLEASE give me CLEAN URLS!

Post by cmb » Tue Aug 14, 2012 8:03 pm

kweku wrote:even if in the long term you find that the process is not 100% achievable', im sure it will be in the future.
I'm quite confident, that it is possible to solve the "still remaining problems" in the near future. If so, it might be considered to integrate that as option to the core in XH 1.6. However, it's up to the plugin developers to make it possible to have clean URLs for the plugins too.
kweku wrote:i often go to http://www.opensourcecms.com/ to see what's out there
We're currently preparing a publicly available demo of CMSimple_XH so we can finally list it there. I'm curious about the voting.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: re: PLEASE give me CLEAN URLS!

Post by cmb » Sat Feb 02, 2013 1:37 pm

Christoph M. Becker – Plugins for CMSimple_XH

Post Reply