"clean" page URLs with newLISP wiki

Notices and updates
Locked
Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

"clean" page URLs with newLISP wiki

Post by Kirill »

Hi there,

I'm not a big fan of URLs of form

Code: Select all

http://www.example.com/index.cgi?page=Page
I'd rather have

Code: Select all

http://www.example.com/Page
It took me 5 mins to get the newLISP wiki to use this form of URLs together with Apache and mod_rewrite.

I used following configuration in httpd.conf (if you use .htaccess, you'd need to modify it a bit, but not much):

Code: Select all

<VirtualHost [...]>
    [...]
    RewriteEngine On
    RewriteRule ^/$ %{DOCUMENT_ROOT}/index.cgi [L]
    RewriteRule ^/index.cgi$ %{DOCUMENT_ROOT}/index.cgi [L]
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-l
    RewriteRule ^/([a-zA-Z0-9\xa0-\xff].*)$ %{DOCUMENT_ROOT}/index.cgi?page=$1 [
QSA,L]
</VirtualHost>
In index.cgi, I just removed references to "index.cgi?page=" in the URLs.

The result can be seen at http://wiki.km.krot.org/.

Of course, this is a quick and dirty hack. A better way would be to check if the environment variable PATH_INFO exists and construct the URL depending on the fact of it's existance.

-- Kirill

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: "clean" page URLs with newLISP wiki

Post by cormullion »

Kirill wrote:Of course, this is a quick and dirty hack. A better way would be to check if the environment variable PATH_INFO exists and construct the URL depending on the fact of it's existance.
Thanks for this! It looks like it will work well.

By strange coincidence, I'm also currently contemplating some code that is to check PATH_INFO and strip out the strings of interest. I've not had any success using the newLISP web server yet, though. But these fixed URIs are supposed to be officially cool. http://www.w3.org/Provider/Style/URI And isn't it also true that Google prefers them?



-- I seem to be always outside my comfort zone these days... :)

Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

Post by Kirill »

Here's some stuff for .htacess-based rewrite rules (for a wiki living under /wiki):

Code: Select all

RewriteEngine On
RewriteBase /wiki
RewriteRule ^$ index.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9\xa0-\xff].*)$ index.cgi?page=$1 [QSA,L]
FileInfo needs to be included in AllowOverride in order to be able to change rewrite rules in .htaccess files.

http://www.krot.org/wiki/. You can verify that this is indeed a newLISP wiki by going to http://www.krot.org/wiki/index.cgi?index

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Good job. I've used some of your suggestions for my current project...!

Locked