Clean and nice URL for Koken CMS

In order to have your Koken CMS use clean and nice url like //www.jr-photo.be/albums/portrait/ instead of //www.jr-photo.be/index.php?albums/portrait/ you can add rewriting rule in the http conf file of your Koken Photo CMS website.

Be sure to have the mod rewrite enabled (sudo a2enmod rewrite).

The rewriting rules need to be put in the directory part of the conf:

<Directory /var/www/koken/koken>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /koken
# Pass images requests back to PHP if they do not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /koken/storage/cache/images(/(([0-9]{3}/[0-9]{3})|custom)/.*)$
RewriteRule . /koken/i.php?path=%1 [L]

# Pass albums requests back to PHP if they do not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /koken/storage/cache/albums(/([0-9]{3}/[0-9]{3})/.*)$
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_URI} !favicon.ico
RewriteRule . a.php?path=%1 [L]

# Do not enable path rewriting for files that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_URI} !favicon.ico

# Redirect everything else to custom site path
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)?$ /$1 [R=301,L]
</IfModule>
</Directory>

<Directory /var/www/koken>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

<IfModule mod_rewrite.c>
RewriteEngine On

# Pass images requests back to PHP if they do not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /koken/storage/cache/images(/(([0-9]{3}/[0-9]{3})|custom)/.*)$
RewriteRule . /koken/i.php?path=%1 [L]

# Pass albums requests back to PHP if they do not exist
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /koken/storage/cache/albums(/([0-9]{3}/[0-9]{3})/.*)$
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_URI} !favicon.ico
RewriteRule . a.php?path=%1 [L]

# Catch root requests (pjax)
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{QUERY_STRING} _pjax=
RewriteCond %{DOCUMENT_ROOT}/koken/storage/cache/site/index/cache.phtml -f
RewriteRule .* /koken/storage/cache/site/index/cache.phtml [L]

# Catch root requests
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{QUERY_STRING} !_pjax=
RewriteCond %{DOCUMENT_ROOT}/koken/storage/cache/site/index/cache.html -f
RewriteRule .* /koken/storage/cache/site/index/cache.html [L]

# Catch site requests (pjax)
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{QUERY_STRING} _pjax=
RewriteCond %{DOCUMENT_ROOT}/koken/storage/cache/site%{REQUEST_URI}cache.phtml -f
RewriteRule . /koken/storage/cache/site%{REQUEST_URI}cache.phtml [L]

# Catch site requests
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{QUERY_STRING} !_pjax=
RewriteCond %{HTTP_COOKIE} !share_to_tumblr=
RewriteCond %{DOCUMENT_ROOT}/koken/storage/cache/site%{REQUEST_URI}cache.html -f
RewriteRule . /koken/storage/cache/site%{REQUEST_URI}cache.html [L]

# CSS / RSS caching
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/koken/storage/cache/site%{REQUEST_URI} -f
RewriteRule . /koken/storage/cache/site%{REQUEST_URI} [L]

# Rewrite any old URLs that still use index.php?/this/that syntax
RewriteCond %{QUERY_STRING} ^/(.*)
RewriteRule ^index.php %1? [R,L]

# Rewrite any old URLs that still use index.php/this/that syntax
RewriteRule ^index.php/(.*)$ $1 [R,L]

# Catch root requests
RewriteRule ^(index.php)?$ /koken/app/site/site.php?url=/&base_folder=/ [L,QSA]

# Do not enable path rewriting for files that exist and mod_pagespeedpage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_URI} !favicon.ico

# For requests that are not actual files
# rewrite to index.php?/PATH
RewriteRule ^(.*)$ /koken/app/site/site.php?url=/$1&base_folder=/ [L,QSA]
</IfModule>
</Directory>

That’s all!

Note that I did find plenty of informations on //kokensupport.com/ to have this working.

That’s all. See it live on my photo website: www.jr-photo.be

Jonathan

Author: jr-photo.be

Brussels Artist Photographer

One thought on “Clean and nice URL for Koken CMS”

Comments are moderated and dofollow link is activated.

Comment rules:
  • Real comments that shows that you have read the post
  • Link only to photography related websites.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.