Tags:
url1Add my vote for this tag create new tag
view all tags

Shortening URLs CategoryTWikiPatches

Question

I have been trying to implement short URLs in view scripts.

I have modified .htaccess, TWiki.cfg, but found a bug in UI::View. Here I propose my solution and ask for your suggestions.

Intended result

Ideally I want my URLs to look like:

http://vitali.web.cs.unibo.it/Main/SomeTopic

instead of

http://vitali.web.cs.unibo.it/cgi-bin/twiki/view/Main/SomeTopic

and

http://vitali.web.cs.unibo.it/Main/

instead of

http://vitali.web.cs.unibo.it/cgi-bin/twiki/view/Main/WebHome

Proposed solution

Changes to .htaccess

I changed .htaccess thusly:

RewriteEngine On
RewriteRule ^(index\.html)$ /cgi-bin/twiki/bin/view/Main/WebHome [L]
RewriteRule ^(\/)$ /cgi-bin/twiki/bin/view/Main/WebHome [L]
RewriteRule ^cgi-bin/(.*)$ cgi-bin/$1 [L] 
RewriteRule ^twiki/(.*)$ twiki/$1 [L]
RewriteRule ^([a-z].*)$ cgi-bin/twiki/bin/$1 
RewriteRule ^([A-Z].*)$ cgi-bin/twiki/bin/view/$1 
RewriteRule ^([A-Z].*)/$ cgi-bin/twiki/bin/view/$1/WebHome

Note that this assumes that all webs are WikiNames and thus begin with capital letters, and all scripts start with lowercase letters.

Changes to TWiki.cfg

I changed TWiki.cfg as follows:

*** dist/twiki/lib/TWiki.cfg    Thu Dec  2 00:24:46 2004
--- TWiki.cfg   Thu Feb 10 20:11:31 2005
***************
*** 63,69 ****
  $scriptUrlPath    = "/cgi-bin/twiki/bin";
  #                   URL path to scripts used to render links.  Change if using redirection to shorten URLs
! $dispScriptUrlPath = $scriptUrlPath;
  #                   URL path to view script used to render links, relative to $dispScriptUrlPath
! $dispViewPath     = "/view";
  #                   %PUBURLPATH% : Public data URL path for TWiki (root of attachments) :
  $pubUrlPath       = "/twiki/pub";
  
--- 63,69 ----
  $scriptUrlPath    = "/cgi-bin/twiki/bin";
  #                   URL path to scripts used to render links.  Change if using redirection to shorten URLs
! $dispScriptUrlPath = "";
  #                   URL path to view script used to render links, relative to $dispScriptUrlPath
! $dispViewPath     = "";
  #                   %PUBURLPATH% : Public data URL path for TWiki (root of attachments) :
  $pubUrlPath       = "/twiki/pub";

Bug found: double slashes in viewauth URL.

Unfortunately, what I've thought so far works for all view URLs and for all scripts I tried except for viewauth.

Everytime I try to access a web with ALLOWTOPICVIEW set I get a spurious double slash in the URL that creates havoc:

http://vitali.web.cs.unibo.it/cgi-bin/twiki/bin/viewauth//TechWebBook/WebHome

instead of what I wanted

http://vitali.web.cs.unibo.it/cgi-bin/twiki/bin/viewauth/TechWebBook/WebHome

Proposed patch to UI::View.pm

There is one line (line 274) in UI::View.pm that adds for no clear reasons (at least to me) a slash in the $pathinfo variable. I simply commented out the line, and everything now seems (seems) to work.

*** dist/twiki/lib/TWiki/UI/View.pm     Wed Aug 25 08:36:15 2004
--- View.pm     Fri Feb 11 00:01:27 2005
***************
*** 270,276 ****
          my $script      = $ENV{'SCRIPT_NAME'};
          my $pathInfo    = $ENV{'PATH_INFO'};
          my $queryString = $ENV{'QUERY_STRING'};
!         $pathInfo    = '/' . $pathInfo    if ($pathInfo);
          $queryString = '?' . $queryString if ($queryString);
          if ($script && $script =~ m|/view| ) {
            $script =~ s|/view|/viewauth|o;
--- 270,277 ----
          my $script      = $ENV{'SCRIPT_NAME'};
          my $pathInfo    = $ENV{'PATH_INFO'};
          my $queryString = $ENV{'QUERY_STRING'};
! # FV 10022005: Removed the following line because it broke URL redirection
! #        $pathInfo    = '/' . $pathInfo    if ($pathInfo);
          $queryString = '?' . $queryString if ($queryString);
          if ($script && $script =~ m|/view| ) {
            $script =~ s|/view|/viewauth|o;

Final request

I would seriously appreciate your comments and objections to my patch and maybe a simpler way to implement the same result. The system now appears to work, but I would hate to find out that there is a subtle bug somewhere or that there existed a simpler way to do the same thing.

Thanks

FabioVitali

Environment

TWiki version: TWikiRelease02Sep2004
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Htaccess, Authentication, Contributing code

-- FabioVitali - 10 Feb 2005

Answer

Just an idea here. What I did was installed cgi-files normally in /cgi-bin/bin into /twiki. Changed the paths in TWiki.cfg. Added this to htaccess in /twiki:

SetHandler cgi-script -->don't need the .cgi

Options ExecCGI ---> cgi enable directory

DirectoryIndex view ---> view acts like index.html

Initially this allows path of www.domainname.com/twiki to get to site.

then any links of course adds /view/webname/topicname to the path. This works if your webhost allows it. I can't see any way yet to lose the /view as it is a required filename as an executable, and you have view...edit...more...etc

-- BruceRProchnau - 19 Feb 2005

Thanks Fabio! That's a long standing issue on one of my servers running CairoRelease and ShorterURLs.

I attempted to make this change in DevelopBranch but found that the line does not exist. Clearly this is something that will need testing for Dakar.

-- MartinCleaver - 19 Feb 2005

nice touch bruce! I like simple, and I can use that without having to have rewrite engine enabled.

Has anybody tried installing the contents of bin into the root html directory? Combine that with view as index and we might get down to the shorted possible...

-- MattWilkie - 20 Feb 2005

There is no reason I can see not to put bin contents into root dir, aside from some problems with images not showing when off a cgi enabled directory. But there probably is a workaround I don't know about. Ran into this uploading from Movable Type into TWiki, path was to TWiki dir and images wouldn't show... I tried in the image dir: Options -ExecCGI that I seen someplace, but didn't work..

-- BruceRProchnau - 21 Feb 2005

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2005-02-21 - BruceRProchnau
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.