Support Centre

Zeus Rewrite Rules User guide

3*3*3*3*3*

Article

Zeus Rewrite Rules User guide

Overview

Request rewriting functionality can be used to change a requested
URL into any other URL by providing a script of rewrite commands for the Zeus Web Server to pre-process every request. This powerful functionality enables you to modify the URL and HTTP headers of a request in any way you wish. The modified request is passed on to be processed in the usual way, returning the requested page.

Note: For rules to be parsed by the server, the rewrite.script file must be placed in the web-root for your site.

This guide is written to highlight the basic differences between
Apache and Zeus's implementation. We have provided a number of stock scripts,
with brief explanations, for some common software packages in use today.

Introduction

For example, the following script illustrates how to change
requests for any HTML files in the /sales directory so that the user receives
them from the /newsales directory instead:

Apache
RewriteEngine on              
RewriteRule ^/sales/(.*)\.html$ /newsales/$1.html
Zeus
match URL into $ with ^/sales/(.*)\.html              
if matched set URL=/newsales/$1.html

In the following example all requests for non-existant .html files
are redirected to index.php:

Apache
RewriteCond %{REQUEST_FILENAME} !-f              
RewriteRule ^[^/]*\.html$ index.php
Zeus
match URL into $ with ^/[^/]*\.html$         
if matched then set URL = /index.php

Common rewrite rules rewritten for Zeus

Wordpress

The following example illustrates the conversion of standard
wordpress rewrite rules:

The scripts below both check and redirct any requests for non
existent files or directories to the index.php file

Apache
RewriteEngine On              
RewriteBase /              
RewriteCond %{REQUEST_FILENAME} !-f              
RewriteCond %{REQUEST_FILENAME} !-d              
RewriteRule . /index.php [L]
Zeus
#Zeus webserver version of basic Wordpress mod_rewrite rules              
map path into SCRATCH:path from %{URL}              
look for file at %{SCRATCH:path}              
if exists then goto END              
look for dir at %{SCRATCH:path}              
if exists then goto END              
##### FIX FOR LOGIN/FORGOTTEN PASSWORD/ADMIN ETC #####              
match URL into $ with ^/wp-.*$              
if matched then goto END              
set URL = /index.php

The Zeus script below permanent 301 redirects any requests for "non-www" URL's to the "www" equivalent for the "domain.co.uk" domain.

Zeus
match IN:Host into $ with ^domain\.co\.uk$             
if matched             
  match URL into $ with ^/(.*)$             
  if matched             
    set OUT:Location  = http://www.domain.co.uk/$1             
    set OUT:Content-Type = text/html             
    set RESPONSE = 301             
    set BODY = Moved             
  endif             
endif

Joomla - Rewriting SEO URLs in ZWS

If you have real paths that match /content/ or /component/ then you
need to check that the request isn't for a real file. Only use this code if you
actually need it because it requires a lot more processing time than the
alternative below. You will need to use this rewrite rule:

match URL into $ with (/content/|/component/)              
    if matched then              
    map path into SCRATCH:path from %{URL}              
    look for file at %{SCRATCH:path}              
if not exists then look for dir at %{SCRATCH:path}              
if not exists then set URL = /index.php              
endif

If you don't have real paths like /content/ or /component/ then you
only need this:


match URL into $ with (/content/|/component/)              
if matched then set URL = /index.php

You need to ensure that in the ZWS rewrite request section, the
option to rewrite URI "Overwriting the Request URI" is set to "Leave URI
unchanged". Joomla splits the URI at "/" to find the options sent to it, so
rewriting must leave the original URI alone.


Silverstripe CMS

The following example illustrates the conversion of standard
Silverstripe CMS rewrite rules:

Original Rules:

RewriteEngine On     
RewriteBase /     
RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)     
RewriteCond %{REQUEST_URI} ^/(.*)$     
RewriteCond %{REQUEST_FILENAME} !-f     
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

Zeus equivalent Rules:

match URL into $ with ^/.*\.(gif|jpg|png|css|js).*$     
if not matched     
    match URL into $ with ^/(.*)$     
    if matched     
        look for file at $1     
        if not exists     
            # Set the default page to be displayed if the URL is not a file or resource     
            set URL = /sapphire/main.php?url=$1     
            goto END     
        endif     
    endif     
endif
Reference material
Official apache rewriting guide
Wordpress permalinks guide

For more advanced use:
Zeus webserver user guide
Apache mod_rewrite guide

Rate This Article

How useful was this article?

Not useful A little useful Useful Very useful Everything I needed