Textpattern Clean URL’s with .htaccess on Zeus Servers

The contents of this article may be out of date. It has been archived and will no longer be updated, comments are closed and the page is provided for reference purposes only.

The company I am working for at the moment has their hosting with Names Co. who use Zeus web server not Apache. This is not much of a problem, or so I thought. I would have stuck with Apache but Zeus has it’s own advantages and disadvantages and the hosting company who have chosen Zeus web server forced the decision.

Zeus does not support mod_rewrite, and ignores .htaccess files. I found this out when installing Textpattern and trying to setup clean URL’s without success. All hope is not lost for clean URL’s on Zeus servers.

Zeus web server does not support .htaccess but does use it’s own scripting in a rewrite.script file. Unfortunately, just copying the Apache .htacess to a Zeus webserver won’t work nor will just renaming it to rewrite.script. A bit of googling and I came across a script written to replace the Drupal .htaccess file on drupal.org this seemed to do the trick however I had installed Textpattern in a subdirectory that was causing problems with the script rewriting the paths of the linked CSS and images. After some more research on Zeus rewrite rules (there is not that much out there) I modified the script so it now supports Textpattern installations installed in a subdirectory or not.

The original textpattern .htaccess file:

#DirectoryIndex index.php index.html

#Options +FollowSymLinks
#Options -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^(.+) - [PT,L]

  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*) index.php

  RewriteCond %{HTTP:Authorization}  !^$
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>

#php_value register_globals 0

The translated Zeus version with support for subdirectory’s:

RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index.  don’t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then

# if you have textpattern installed in a subdirectory uncomment
# this bit and replace textpattern with the subdirectory name
# match SCRATCH:REQUEST_URI into $ with ^/textpattern(.*)
# if matched then
# set URL = /textpattern/index.php$1
# endif
# else

set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

The above will allow clean URL’s but is not guaranteed to replicate all the functions of the original Textpattern file. As you can see Zeus uses a lot more code to achieve the same function than Apache.

The above script assumes you have installed Textpattern in the web root and not a subdirectory. If you have installed Textpattern in a sub directory uncomment (remove the # from the beginning) the lines as described in the script. The script then assumes you have installed Textpattern in a subdirectory called textpattern. If this is not the case in the script change the two instances (bold text) of textpattern in the script.

Lastly rewrite.script must be placed in the websites root directory (not in the subdirectory) to function in either scenario unlike .htaccess that may be placed within a folder.

Addendum 18/02/09: After some more testing it turns out the subdirectory edit works when setting Textpattern to use /title as the URL mode. This works for pages reached by this URL but causes problems with URL’s on the index page. Will look at solving this issue and updating the script as soon as possible.

This article was posted on 13 February 2009 in Textpattern

comments

What you have had to say about all this...

Hi Mark. I’m having this very same problem, while attempting to build a TextPattern site using Names Co web hosting, and yours is the online site I’ve found that seems to come close to addressing it. Were you ever able to solve the problem with the (disappearing) site index page?! Thanks, Tom

- tom

Hi Tom, In the end I switched back to using messy urls for this project. Some of the Zeus documentation suggests parts of htaccess specification are supported but it seems very limited. I don’t know enough about Zeus Dynamic Control Files to fix the issue here and didn’t get much help from Names Co; they seemed as much in the dark as I was. Good luck and let me know if you find a solution.

- markinns

Hi Mark,

Thanks for posting this.

Am I correct in reading from your ‘Addendum 18/02/09…’ that if I have an install of Textpattern where it is *not* in a subdirectory, but installed in the usual manner—with it’s index.php in the root and /textpattern directly beneath the root, that you think your file will work?

I know you can guarantee it of course, but just trying to see if this is a solution for me too.

Thanks lots in advance for any comment!

Cheers -Alan

- Alan

If textpattern is installed in the root directory then the Zeus script should work fine for you as far as I am aware.

- markinns

Thanks Mark!

- Alan

That's the end of this article. I hope you found it useful. If you're enjoyed this article why don't you have a look around the archives, where you can find some more tutorials, tips and general ramblings.