"clean" page URLs with newLISP wiki

Started by Kirill, April 12, 2008, 10:51:31 AM

Previous topic - Next topic

Kirill

Hi there,



I'm not a big fan of URLs of form http://www.example.com/index.cgi?page=Page

I'd rather have 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):



<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-9xa0-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/">//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

#1
Quote from: "Kirill"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">//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

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



RewriteEngine On
RewriteBase /wiki
RewriteRule ^$ index.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9xa0-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/">//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">//http://www.krot.org/wiki/index.cgi?index

cormullion

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