Welcome

BoltWire is a content management system developed by Dan Vis.

Welcome Tour
Documentation
Mailing List



Popular Posts

Version 5.11 Released
May 26, 2016

Big Changes Coming Soon...
April 28, 2016

Catching Up
April 6, 2016



Other Sites

Here's some other sites by Dan Vis:

Alexa Echoes
Join my adventures developing for Amazons exciting new voice platform.

Firefly Spot
Personal rambling about new gadgets, technology news, and space travel.

FAST Missions
My ministry hub, with news and updates about our online school.

You can follow him at www.danvis.info.

CleanURL's

Documentation > Concepts > CleanURL's

BoltWire offers optional support for cleanurls so that long, complex urls like:

          www.site.com/field/index.php?p=some.page

can be written into something more simple like:

          www.site.com/field/some/page

or even

          www.site.com/some/page

This sometimes helps with search engine optimization, as there are engines that do not index urls with special characters such as a question mark. It also makes things easier to type!

We'll give two configuration examples below, depending on whether you have 1) just one field (site) running off your BoltWire installation, or 2) you have multiple fields (sites). The settings below may need to be modified on some servers.

Single Field

First, create a .htaccess file in each root web directory with the following content:


RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{THE_REQUEST} !/field/files/(.*)\.
RewriteCond %{THE_REQUEST} !/boltwire/farm/img/(.*)\.
RewriteRule ^(.*)$ field/index.php?p=$1 [QSA,L]

This changes any url to your site unless it is in your files directory or a farm image. Next, add these lines to field/index.php before calling the engine:

$cleanURL='http://www.site.com/';
$fieldURL='http://www.site.com/field/';

Note: If you have a non-standard installation you may also need to set the $farmURL variable in order to get farm img and pub files, and to get CSS links to work as well.

Lastly, to go to "some.page" just type http://www.site.com/some/page in your browser. Much nicer than http://www.site.com/field/index.php?p=some.page, hey?

Here is another configuration suggested by a user:


RewriteEngine on
# Add www
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Skip images in the farm folder
RewriteRule ^boltwire/farm/img/.*$ - [L]
# Skip the files folders of all fields
RewriteRule ^field/files/.*$ - [L]
# Rewriting index.php queries
RewriteRule ^field/(.*)$ field/index.php?p=$1 [QSA,L]
# Redirecting / to a field
RewriteRule ^$ /field/ [R=301,L]

Farm Installation

First, create a .htaccess file in each field folder with the following content. Make sure there are no (conflicting) rewrite lines in any root directory .htaccess file you may have:


RewriteEngine On
RewriteBase /field
RewriteRule ^$           index.php  [L]
RewriteRule ^index\.php$ index.php  [L]
RewriteRule ^(.*)$ index.php?p=$1  [QSA,L]

Then, add these lines to field/index.php before calling the engine:

$cleanURL='http://www.site.com/field/';
$fieldURL='http://www.site.com/field/';

Note: If you have a non-standard installation you may also need to set the $farmURL variable in order to get farm img and pub files, and to get CSS links to work as well.

Then to go to "some.page" just type http://www.site.com/field/some/page in your browser.

Multiple Domains, one code base


Alternately, you can use a single .htaccess installation in the root directory to redirect the browser to multiple fields which are mapped to different domains using a setup something like the following:


RewriteEngine On
Options +FollowSymlinks
RewriteRule ^boltwire/.*$   -   [L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example1(.*)
RewriteCond %{REQUEST_URI} !files/(.*)\.
RewriteRule ^(.*) field1/index.php?p=$1 [QSA]
RewriteCond %{HTTP_HOST} ^www\.example2.org(.*)
RewriteCond %{REQUEST_URI} !files/(.*)\.
RewriteRule ^(.*) field2/index.php?p=$1 [QSA]

and add the cleanURL and fieldURL notes to the field1/index.php and field2/index.php as mentioned above.

The conditions check which field is accessed (HTTP_HOST) and allow access to the files directory (REQUEST_URI) which is essential to get uploads working.

Using the same index.php locally and remotely

As your local server and your remote server have different host names, you would normally need two distinct index.php files. The following code in index.php works for both as it dynamically fetches the current host name:


$cleanURL='http://' . $_SERVER['HTTP_HOST'] . '/field/';
$fieldURL='http://' . $_SERVER["HTTP_HOST"] . '/field/';

Note: If you have a non-standard installation you may also need to set the $farmURL variable in order to get farm img and pub files, and to get CSS links to work as well.

How It Works

There are two parts to cleanurls. First, getting your apache server to do the URL aliasing (which is where the real work is) and then second, getting BoltWire configured to work with the new urls.

Apache has something called a rewrite engine which allows you to set up various rules to do automatic URL aliasing. The .htaccess file turns this on and tells it how to "rewrite" incoming urls so they map to different locations, invisibly.

Then, you have to tell BoltWire what kind of cleanUrl links to output so it works with this aliasing. It also needs to know where the field actually is on the server.

These rewrite rules are similar to regular expressions, but can be even more tricky. So make sure to test things thoroughly on your system. If you have a farm installation with more than one field, be sure to check all fields after changing a .htaccess file. Also check things like plugins, skins, and graphics to make sure everything is running.

Doesn't Work?

It seems different servers require different settings. Not sure exactly what the differences are. But getting the wrong settings can be a real problem--likely making some or all of your site inaccessible. To fix it, just upload a blank/empty .htaccess and Apache should work again. Then turn off the cleanUrl settings in field/index.php.

TAGS:
To leave a comment, please login using your Facebook account: