menu

The .htaccess file

.htaccess for la.plume micro CMS

Previous to 21st November 2018.


la.plume micro CMS puts an .htaccess file in the 'root' installation folder. The file is written when admin/setup is submitted. That is why the system is best installed on Apache web server, not Windows IIS server (Windows does not support the use of .htaccess). Some hosting accounts, even on Apache, do not allow the writing or customisation of .htaccess - the file may already exist but is not writeable.

The system can be run with no .htaccess file. The pages will then display with a .php file extension. If the .htaccess file is present (and writeable) the system runs normally with no .php file extension.

If you can't see the .htaccess file...

On some web hosting packages the .htaccess file is not visible using an FTP client program. This can often be corrected by enabling server side filtering in the FTP client program and setting the remote filter as -rtaF (the precise details may vary).

The .htaccess file explained:

# Block direct access to scripts, text files and images folder
RewriteCond %{REQUEST_URI} ^/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/inc/inmenu\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/admin/list\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/comments/([^/.]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/img/$
RewriteRule .* - [F]
#
# (1) Intercept and redirect requests that are not for the '/admin/' pages
#
# EXTERNAL REDIRECT 1 (LIMIT HOME PAGE TO SINGLE URL)
# If '/index.php' is at the END of the requested path, redirect to '/'
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# EXTERNAL REDIRECT 2
# If request is 'GET /page.php HTTP/1.1' redirect to '/page'
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+)\.php\ HTTP/
RewriteRule ^([^/.]+)\.php$ http://www.example.com/$1 [R=301,L]
#
# EXTERNAL REDIRECT 3 (ONLY FOR WEB ROOT)
# For websites beginning with www
# If request does not include www, redirect to URLs with www
# (reversible for non-www websites: redirect from with-www to without)
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# (2) Internal rewrites
#
# INTERNAL REWRITE 1 (home page)
# If request is '/' internal rewrite to '/index.php'
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /index.php [L]
#
# INTERNAL REWRITE 2 (search page)
# If request is 'search?terms=anything' internal rewrite...
# to '/search.php?terms=anything'
RewriteCond %{REQUEST_URI} ^/search$
RewriteCond %{QUERY_STRING} ^terms=(.*)$
RewriteRule ^search(.*)$ /search.php?%1 [L]
#
# INTERNAL REWRITE 3 (other pages)
# If the request is 'GET /page HTTP/1.1' internal rewrite to '/page.php'
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+)\ HTTP/
RewriteRule ^([^/.]+)$ /$1.php [L]

The .htaccess file (typical)

*From v7.5: if an .htaccess file exists, the lines shown green allow resubmission of setup to update the .htaccess file while preserving extra rules you may have added for other purposes, canonical domain etc.

# BEGIN la.plume
AddDefaultCharset UTF-8
ErrorDocument 404 /error404.php
<IfModule mod_rewrite.c>
RewriteEngine On
#
RewriteCond %{REQUEST_URI} ^/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/inc/inmenu\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/admin/list\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/comments/([^/.]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/img/$
RewriteRule .* - [F]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+)\.php\ HTTP/
RewriteRule ^([^/.]+)\.php$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /index.php [L]
#
RewriteCond %{REQUEST_URI} ^/search$
RewriteCond %{QUERY_STRING} ^terms=(.*)$
RewriteRule ^search(.*)$ /search.php?%1 [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+)\ HTTP/
RewriteRule ^([^/.]+)$ /$1.php [L]
</IfModule>
# END la.plume

If the lines shown green (# BEGIN la.plume and # END la.plume) are manually deleted from the .htaccess file, resubmission of setup will create a completely new (default) .htaccess file.

If you write extra rules they should be placed before # BEGIN la.plume so they are preserved when setup is resubmitted.

Downloads since Sept 2011: 18,794