A static index page, a plone site and apache
January 2018
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.
Recent Entries
Recent Comments
Recent Trackbacks
OpenBSD (9 items)
BSD (0 items)
FreeBSD (19 items)
Linux (3 items)
Security (3 items)
Python (22 items)
Zope (13 items)
Daily (144 items)
e-shell (9 items)
Hacks (14 items)
PostgreSQL (3 items)
OSX (8 items)
Nintendo DS (0 items)
enlightenment (0 items)
Apache (3 items)
Nintendo Wii (1 items)
Django (24 items)
Music (12 items)
Plone (7 items)
Varnish (0 items)
Lugo (2 items)
Sendmail (0 items)
europython (7 items)
Cherokee (1 items)
self (1 items)
Nature (1 items)
Hiking (0 items)
uwsgi (0 items)
nginx (0 items)
cycling (9 items)
Networking (1 items)
DNS (0 items)

Syndicate this site (XML)

RSS/RDF 0.91

13 febrero

A static index page, a plone site and apache

or how to add a splash screen to your plone site

IMPORTANT: This is probably one of the most dirty hacks than could appear in your thoughts when thinking about implementing a plone site! Use at your own shame and risk!!!

Ok, after such an advice, let me introduce you to my problem. For one of our latest Plone sites, we had a very ugly requirement. The site must have a splash screen that should be shown to the user on first load, and each time the user tries to reach the site. That is, the splash will appear when I open whateverdomain.com in my browser, then I'll be able to follow the splash screen links to navigate to the plone site itself and I'll be able to keep navigating through the site as usual. If I (for some strange reason) try to get to whateverdomain.com/news directly, instead of the news, I'll get the splash screen.

Well, I didn't like the idea too much, but if that's what the customer wants, that's what the customer will get.

After setting up the Plone site and Apache, as usual, I ended with a VirtualHost configuration pretty similar to this one:

<VirtualHost *:80>

      ServerAdmin admin@server.com
      ServerName whateverdomain.com
      ServerAlias www.whateverdomain.com
      DocumentRoot /usr/local/www/apache22/data/whateverdomain.com

      ErrorLog /var/log/apache22/whateverdomain.com-error.log
      CustomLog /var/log/apache22/whateverdomain.com-access.log combined

      <IfModule mod_rewrite.c>
          RewriteEngine On
          # prevent access to ZMI through apache
          RewriteRule ^/(.*)/manage(.*) \
          RewriteRule ^/manage(.*) \
          RewriteRule ^/(.*) \
              http://localhost:8089/VirtualHostBase/http/%{SERVER_NAME}:80/whateverdomain/VirtualHostRoot/$1 [L,P]


Then I just saved the index.html file containing the splash screen inside the VirtualHost DocumentRoot (/usr/local/www/apache22/data/whateverdomain.com), and then I tweaked the VirtualHost configuration a little bit, adding some RewriteCond options to the mod_rewrite configuration:

RewriteCond %{HTTP_REFERER} ^http://(www\.)?whateverdomain.com.*$
RewriteCond %{REQUEST_URI} !^/index.html
RewriteCond %{REQUEST_URI} !^/splash_img(.*)
RewriteCond %{REQUEST_URI} !^/splash_css(.*)
RewriteRule ^/(.*) \
        http://localhost:8089/VirtualHostBase/http/%{SERVER_NAME}:80/whateverdomain.com/VirtualHostRoot/$1 [L,P]

Here, I've added some conditions to the rewrite rule that will send the request back to Zope, and get the contents from the application server.

First condition:

RewriteCond %{HTTP_REFERER} ^http://(www\.)?whateverdomain.com.*$

will check for the HTTP_REFERER header, checking if it is the current domain name (with or without www). With this rule we ensure that only requests that match the condition will continue to the final RewriteRule (meaning that, more than probably, you are clicking on links on the site).

The next three conditions:

RewriteCond %{REQUEST_URI} !^/index.html
RewriteCond %{REQUEST_URI} !^/splash_img(.*)
RewriteCond %{REQUEST_URI} !^/splash_css(.*)

are used to check if the request contains those strings on its URI, that is, the index.html splash page, links to the images used in the page and css files too. In fact, we could have used something like:

RewriteCond %{REQUEST_URI} !^/splash(.*)

That would be more generic (for directories containing flash files, for example).

A quick apache restart and it worked!. When trying to access any page within the Plone site directly, the splash screen appeared. If I did follow the links on it, everything worked as expected.

But, the problems appeared soon. What about, for example, links sent by plone to recently created users, by mail? Once you register yourself to such Plone site, you get an email with the link to finish the registration process, but if you click on the link (with the apache configuration described above), you will end in the splash screen (with no choice to get to the confirmation page).

To solve this problem, we only have to add some more RewriteCond magic to the VirtualHost configuration:

RewriteCond %{REQUEST_URI} ^/login [OR]
RewriteCond %{REQUEST_URI} ^/logout [OR]
RewriteCond %{REQUEST_URI} ^/logged_out [OR]
RewriteCond %{REQUEST_URI} ^/password(.*)
RewriteCond %{HTTP_REFERER} ^http://(www\.)?whateverdomain.com.*$
RewriteCond %{REQUEST_URI} !^/index.html
RewriteCond %{REQUEST_URI} !^/splash_img(.*)
RewriteCond %{REQUEST_URI} !^/splash_css(.*)
RewriteRule ^/(.*) \
        http://localhost:8089/VirtualHostBase/http/%{SERVER_NAME}:80/whateverdomain.com/VirtualHostRoot/$1 [L,P]

In those lines you should recognize some of the tipical plone links (login, logout, password, etc). The lines with the [OR] flag at the end will be processed secuentially until reaching the HTTP_REFERER check. That means that the request will be sent to Zope if:

  • The URI has "/login" in it OR
  • The URI has "/logout" in it OR
  • The URI has "/logged_out" in it OR
  • The URI has "/password" in it AND
  • The HTTP_REFERER is whateverdomain.com (with or without www) AND
  • The URI has not "/index.html" in it AND
  • The URI has not "/splash_img" in it AND
  • The URI has not "/splash_css" in it

As I've said before, I didn't like the Idea of the splash screen too much, but if you are in a hurry and you need to set up something like that, perhaps you will find this tip useful.

Posted by wu at 20:48 | Comments (0) | Trackbacks (0)
<< Books: Practical Plone 3 | Main | Sun Microsystems y la ortografía española >>
There are no comments.
Please send trackback to:http://blog.e-shell.org/137/tbping
There are no trackbacks.
Post a comment