This question about Configuration: Asked

Short URL htaccess code FAILs with Foswiki 2

Foswiki 1.1.9

I have a Foswiki 1.1.9 installation working with short URLs (no /bin/view) on Dreamhost. (http://baaptfwi119.dreamhosters.com/)

It is using Short URL code from Support/ShorterUrlCookbook in the top level .htaccess file.

RewriteEngine On
RewriteBase /             
RewriteRule ^([^/.]+)$ /bin/xview/Main/$1                      [L,NE]
RewriteRule ^Main/([^/.]+)$ http://baaptfwi119.dreamhosters.com/$1                   [L,NE]
RewriteRule ^(Sandbox|System|Trash|TWiki|Drafts)/(.*?)$ /bin/xview/$1/$2    [L,NE]
# Special rule for Main
RewriteRule ^bin/view/Main/([^/.]+)$ http://baaptfwi119.dreamhosters.com/$1             [L,NE]
RewriteRule ^bin/view$ http://baaptfwi119.dreamhosters.com/                         [L,NE]

# do not skip index.html - instead we are using a static (quickly loading) file
RewriteRule ^$ /bin/xview/Main/                              [L,NE]

For Foswiki 1.1.9, this works.

Foswiki 2.1.2

I upgraded the FW installation to 2.1.2. (http://baapt.dreamhosters.com/bin/view/Main)

If I try to use the short URLs (e.g. http://baapt.dreamhosters.com), I get an error:
The requested URL / was not found on this server.

The only differences in the .htaccess file are in the hostname portion of the URL:

diff baapt_foswiki/.htaccess baapt_foswiki119/.htaccess
10c10
< RewriteRule ^Main/([^/.]+)$ http://baapt.dreamhosters.com/$1                   [L,NE]
---
> RewriteRule ^Main/([^/.]+)$ http://baaptfwi119.dreamhosters.com/$1                   [L,NE]
13,14c13,14
< RewriteRule ^bin/view/Main/([^/.]+)$ http://baapt.dreamhosters.com/$1             [L,NE]
< RewriteRule ^bin/view$ http://baapt.dreamhosters.com/                         [L,NE]
---
> RewriteRule ^bin/view/Main/([^/.]+)$ http://baaptfwi119.dreamhosters.com/$1             [L,NE]
> RewriteRule ^bin/view$ http://baaptfwi119.dreamhosters.com/                         [L,NE]

The only other change is from FW 1.1.9 to FW 2.1.2

When I turn off the "short URL" code, everything works as expected.

Given that the only difference I can see is in the Foswiki underpinnings, I am blaming this on FW unless someone can give me a very good reason to blame something else.

-- VickiBrown - 16 Jun 2016

Vicki, do you have any idea why the view script has been copied to xview? Foswiki 2.x uses the recovered script name as the "action", and Foswiki has no idea what an "xview" is.

I don't have access to dreamhost or even a web server configured with .htaccess, but I was able to make the "xview" script to work by hardcoding the action.
--- bin/view    2016-06-28 22:05:09.158922345 -0400
+++ bin/xview   2016-06-29 22:40:38.362872849 -0400
@@ -20,7 +20,7 @@
     my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' );
     @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir;
     require $setlib;
-    $action =~ s/\..*$//;    # Remove eventual file extension
+    $action = 'view';
     $ENV{FOSWIKI_ACTION} = $action;
 }
 

-- GeorgeClark - 30 Jun 2016

As per Support/ShorterUrlCookbook Option 2a: Complete example as .htaccess:

The file bin/xview is a copy of bin/view. For this specific site, Main web is the main public web with a special "root" url: http://site.com/WebHome will access http://site.com/bin/view/Main/WebHome.

If you look carefully at the htaccess code, I'd say that the copy of view as xview is there to prevent a redirect loop.

RewriteRule ^([^/.]+)$ /bin/xview/Main/$1
...
RewriteRule ^bin/view/Main/([^/.]+)$... http://x.y.com$1...
RewriteRule ^bin/view/$... http://x.y.com/  ...         
RewriteRule ^$ /bin/xview/Main/ .     

Tasks/Item14102 filed. Design by Omniscience is wrong.

-- VickiBrown - 01 Jul 2016

So... I ended up editing xview
    # $action =~ s/\..*$//;    # Remove eventual file extension
    $action = 'view';

and using this .htaccess file
  # This enables access to the documents in the Foswiki root directory
      Order Allow,Deny
      Allow from all
      Deny from env=blockAccess

Options +FollowSymLinks 
RewriteEngine On
RewriteBase /             

RewriteRule ^([^/.]+)$ /bin/xview/BAAPT/$1                      [L,NE]
RewriteRule ^(BAAPT|Main|Sandbox|System|Trash|TWiki|Drafts)/(.*?)$ /bin/xview/$1/$2    [L,NE]
# Special rule for BAAPT
RewriteRule ^bin/view/BAAPT/([^/.]+)$ http://wiki.baapt.org/$1             [L,NE]
RewriteRule ^bin/view$ http://wiki.baapt.org/                         [L,NE]

# do not skip index.html - instead we are using a static (quickly loading) file
RewriteRule ^$ /bin/xview/BAAPT/                              [L,NE]

I decided to use Main as a Foswiki-typical web; that is, it's %USERWEB% and doesn't contain very much local data other than users and groups and shared preferences. My primary data web is BAAPT, and the unmodified URL (http://wiki.baapt.org) goes there.

I also decided that I didn't like removing the web name (something the cookbook was suggesting). That is, I did not try to support:
http://site.com/WEB/WebHome             => http://site.com/WebHome

This made the whole process easier.

-- VickiBrown - 07 Oct 2016

+1. Eliminating the web name is very non-standard. I never had heard of that until you pointed it out. It would probably be best to change the ShorterUrlCookbook to drop that recommendation.

-- GeorgeClark - 07 Oct 2016
 

QuestionForm edit

Subject Configuration
Extension
Version Foswiki 2.1.2
Status Asked
Related Topics
Topic revision: r8 - 07 Oct 2016, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy