Welcome

BoltWire is a content management system developed by Dan Vis.

It's innovative architecture combined with best in class forms processing gives you complete control over every aspect of how your site works.

BoltWire doesn't just let you change content--it lets you change the engine itself right through your browser!


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

Posted October 15, 2015
Share this post:


If you don't know what cleanurl's are, it is using server rewrite rules to change ugly urls into pretty ones. For example, the "real" url for our blog is:

http://www.boltwire.com/index.php?p=blog

But with cleanurl's enabled, you see something different in your browser. Looks a bit "cleaner", doesn't it? And they say search engines like it too!

http://www.boltwire.com/blog

BoltWire has supported cleanurls just fine for a long time, but I've never used them on the BoltWire site because .htaccess files give me headaches. I don't really know much about Apache servers in general and url rewriting more specifically. I could hobble together code from cut and pastes around the web--but that was about it. But now, I think I'm starting to get it!

Here's a few tips if you are trying to get them to work on your site:

1) Put your .htaccess file in the field directory. This way it won't interfere with files in other directories on your server.

This is important if you have add-on domains for example. Or a shared folder where you put resources for multiple sites. Or even to access the little boltwire.gif in your boltwire directory. This step was a huge help for me!

2) Try this for your .htaccess file:

Options -Indexes FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://www.boltwire.com/index.php?p=$1 [P,QSA,L]

The first couple lines turn the rewrite engine on (obvious) and sets a couple options (also obvious). This basically gets things going.

Line three basically checks to see if the requested file exists in the field folder. The !-f means not found. So if it matches this condition, it continues to the rewrite rule. Otherwise it just passes the url along as is. This helps prevent links to images or media in your field folder from being incorrectly rewritten. It also helps protect against rewrite loops. Oh, and another nice thing--if someone uses the full url with the index.php part, that will still work as well!

Line four basically inserts the "index.php?p=" into any url that passes through the condition in the line above: ie, not found. The flags include p for proxy (don't change what shows in the browser), qsa for query string allowed (pass any get variables along), and l for last (you're done).

3) The first two steps will get apache to translate simple urls into their corresponding "real" urls, but you need to take one more step. That is, you want the links that are displayed on your site to use these simpler urls. This is the part BoltWire does.

To turn it on, add this line to your index.php file in the field, somewhere before calling the engine:

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

Basically, if set, BoltWire uses this value in all internal links, instead of the normal full script path. That is, it cuts out the index.php part. It also changes dots to slashes.

So if you try these three things you might just be able to get cleanurls to work. It worked on this site!

Posted by Dan Vis on 10/15/15
I should add... No Promises! Rewrite rules may work differently based on your server configuration. But it sure helps to at least know what you're doing! If anyone has suggestions, comments, or feedback--please feel free to add them below!

Posted by Dan Vis on 10/16/15
Ok, back again. While I had no problems at all with my addon domains, I had a devil of a time getting my main domain to work! The complexity came in because that site's pages were in a field folder (just like the other domains) but the site url resolved to the root directory instead of the field directory.

Note: If you only have one domain and you are using the standard BoltWire installation, which puts each field in a folder, you will need to follow this approach instead of the suggestions above--which only work for addon domains.

The Solution
So here's how I got this to work:

1) In the root directory create an index.php file to forward visitors to /field/index.php. I used this simple code:


<?php
header("Location: http://www.mydomain.com/myfield/main");
header("Content-type: text/html");
print_r("<html><head><meta http-equiv=Refresh></head><body></body></html>");

If you need to do this anyway, and don't want cleanurls, make sure you fix the full script path. That is, be sure to include the index.php part.

Basically, this file lets you type www.mydomain.com into the browser bar instead of www.mydomain.com/myfield.

2) I didn't need any .htaccess file in the root directory.

3) In the field directory I created this .htaccess file:


Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?p=$1 [QSA,L]

I'm not sure why, but the .htaccess file I put in the various addon field folders simply refused to work. Changing the * to a + was the key to finally getting it functional. Evidently some kind of loop was happening otherwise. I also realized the P flag isn't necessary. Don't even need the L flag if this is your only rewrite rule.

And for an added bonus, this rewrite rule is fine for the addon domains as well. In other words, I was able to put this in every field (addon or main domain, webspace or localhost) and it just works.

Also note, that while cleanURL's work as intended, uglyURL's work too. I suppose another rule could be added to forcefully redirect (R=301) uglyURL's, but I'm not going to even chance messing up what I have!

4) Just put the standard BoltWire cleanurl setting in your /field/index.php file. This snippet is nice because it work both on your webspace and in your localhost.


$cleanURL = 'http://' . $_SERVER['HTTP_HOST'] . '/myfield/';

SSL Certificates
If you have ssl, you just need to make sure steps one and four use https instead of http. I also put this line in my /field/index.php to ensure SSL:


if ($_SERVER['HTTPS'] != 'on') {
     $redirect= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     header("Location:$redirect");
     }

Concluding Thoughts
First, there may be better ways to do this and my syntax is probably not perfect. If you have suggestions, I'm more than open to hear them. This is an often requested feature and I'd like to make sure any solution we present is as perfect and universal as possible. But it DOES work for me.

I do plan to move the how to content of this to the cleanURL's tutorial eventually. So any helpful ideas, comments, or feedback on how to strengthen this would ultimately improve our BoltWire documentation.

Because this .htaccess file works so well in every situation (whether cleanurl's are on or not), the idea occurred to me we could automatically include it when we create a new field via the start.php script. Then turning on cleanURL's could just be a simple site.config option. In fact, perhaps it should be turned on by default... Could be issues, but it seems easy.

And while we are at it, what if our start.php script had a checkbox allowing you to specify if an account is the main domain (vs an addon domain), and if so, automatically create the root index.php file above. (It would first check to make sure that file doesn't already exist, to avoid overwriting it). Seems trivial, but sometimes the smallest things become the biggest headaches.

Similar with SSL. Turn on SSL in site.config and everything is fixed. Boom. Done.

All these ideas certainly go with #1 in our BoltWire philosophy. Any thoughts on this?

Last, now that I've got everything working I'm not going to touch a thing... At least for awhile...

Posted by Dan Vis on 10/16/15
For whatever it is worth, I've already made the changes to start.php to create the .htaccess and index.php forwarders automatically. Works like a charm!

I created a new site using the site creator in about 3 seconds. Logged in as an admin and set cleanurls to true in site.config. Then, typed localhost in my browser and boom--up popped the site with clean urls. Awesome!

Expect this in the next release...

I do not think, however, I will set up ssl this way however as it crashes a site if ssl is not working--and then you can't even get in to turn it off! Plus it is easy enough to do in a config file or something for more advanced admins. Will probably release as a plugin or post it as a code snipped somewhere.

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

About the Author

Dan Vis is intrigued with tomorrow. He is a speaker, author, and developer. Here, he writes about gadgets, online learning, space travel, and the future in general.

He is the creator of BoltWire, a paradigm-busting CMS. He suspects Alexa may be a turning point in technology and blogs about it at AlexaEchoes. He stays busy at FAST Misions, where he operates an online school with students from around the world.

You can learn more here: www.danvis.info.