Personal tools
Views

FAQ/Installation/Pretty URLs

From CMSMS

This page in: English - Deutsch - Français - Svenska - Русский - Norsk - Polski - Nederlands - Español - Lietuvių

CMS Made Simple 0.13 and higher come with support for Clean Hierachical URL's

Contents

Step 0 - Finish installation

If you are reading this, you may have missed the activation of the pretty URLs in the optional settings of the installation procedure.

Step 1 - .htaccess file

Create or modify an existing .htaccess file and add/replace with the following. Certain server configurations may require you to add 'RewriteBase /' after the 'RewriteEngine on' command. If your CMS Made Simple installation is in a subdirectory, you'll need to replace RewriteBase / with RewriteBase /cms/ (where /cms/ is the subdirectory name). Also make sure to check your FTP settings to transfer the file as Encoding: ASCII. (For those using Dreamweaver, you may have to use another FTP software.)

No file extension

This configuration will not show a file extension on page URLs. The URLs will look something like www.example.com/page1/, and if use_hierarchy is turned on, nested pages (subpages) will have URLs like www.example.com/page1/page11/)

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

.htm page extension

This configuration will use a .htm extension for the pages. Pages will have URLs like www.example.com/page1.htm, and if use_hierarchy is turned on, nested pages (subpages) will have URLs like www.example.com/page1/page11.htm)

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# RewriteCond %{REQUEST_URI} !/$
# RewriteCond %{REQUEST_URI} !\.
# RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).htm$ index.php?page=$1 [QSA] 

Save the file and upload it to your site's root as '.htaccess' (no file extension!).

Note: if you are using the News module and want publish a rss feed than you will have the following problem if you use an extension. Normally your feed is available under http://host/News/rss but with mod_rewrite turned on the server will not find anything because http://host/News/rss is not rewritten to http://host/index.php?page=News/rss. You can solve the problem in two ways.

  1. add an extra rule just before the first RewriteRule:
    RewriteRule ^News/rss(.+)$ index.php?page=News/rss$1 [S=1]
    This rewrites just the rss feeds to the thing you need. You can add extensions like .xml or .rss
  2. use a more general rewrite rule:
    RewriteRule ^(.+)(.html)?$ index.php?page=$1 [QSA]
    Now all pages with or without extension .htm will work.


Step 2 - config.php changes

Now make the following changes to the "URL Settings" section of your config.php file.

(Note: If you have already followed the Install Instructions to "set your config.php back to a read-only state" you may need to set it back to 666 or 777 temporarily in order to edit and save changes to config.php)

#------------
#URL Settings
#------------

#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
$config['assume_mod_rewrite'] = true;

#Extension to use if you're using mod_rewrite for pretty URLs.
$config['page_extension'] = '/';

#If you don't use mod_rewrite, then would you like to use the built-in
#pretty url mechanism?  This will not work with IIS and the {metadata} tag
#should be in all of your templates before enabling.
$config['internal_pretty_urls'] = true;

#If you're using the internal pretty url mechanism or mod_rewrite, would you like to
#show urls in their hierarchy?  (ex. http://www.mysite.com/parent/parent/childpage)
$config['use_hierarchy'] = true;

#If using none of the above options, what should we be using for the query string
#variable?  (ex. http://www.mysite.com/index.php?page=somecontent)
$config['query_var'] = 'page';

If you're using the .htm page extensions, replace '/' above with '.htm'.

Step 3 - {metadata} plugin call

Add the {metadata} plugin call to the <head> section of your templates. This will automatically insert the base href tag to your site's root so that relative paths to files and images function as expected.

The use_hierarchy setting employed in the config file (see step 2) will convert nested page URLs to display in a heirachical manner (www.example.com/parent/child/ as opposed to www.example.com/child).

Don't worry about having to change any previously advertised URLs as both these forms will still work!


LightTPD configuration

If you are using LightTPD instead of Apache, the following configuration setting should work. This should go into your lighttpd.conf file.

url.rewrite-final = (
  "^/(admin)/(.*)$" => "/$1/$2",
  "^/([^.?]*)$" => "/index.php?page=$1"
)

Optional: LightTPD configuration that works with and without trailing slashes (e.g. /admin will work) and supports /alias, /alias/, and /alias.htm for accessing pages

url.rewrite-final = (
 "^/(admin.*)$" => "/$1",
 "^/(uploads.*)$" => "/$1",
 "^/([^.?]*)(\.htm)$" => "/index.php?page=$1",
 "^/([^.?]*)$" => "/index.php?page=$1"
)



This page in: English - Deutsch - Français - Svenska - Русский - Norsk - Polski - Nederlands - Español - Lietuvių