How to setup SEO friendly URLs for WordPress on Zeus

Up until a year ago I'd only ever used Apache to host websites. At Oxeye Daisy we host on Zeus webservers. After a lot of fruitless searching on the internet for guides on how to setup SEO friendly permalinks for WordPress hosted on Zeus I stumbled upon the relevant code. I've finally got around to tweaking and commenting it. I thought I'd post it here in case anyone else is having the same trouble.

First you need to go to your WordPress admin page and set up the permalink structure in Options > Permalinks. I've set mine to /%year%/%monthnum%/%day%/%postname%/ but you may want something different.

The notes in the script assume the requested URL to be http://www.domain.co.uk/blog/2007/10/31/an-example-post/?color=red I've added the GET queries so you can see how they are handled, they're not used in WordPress. This URL is then translated into http://www.domain.co.uk/blog/index.php/2007/10/31/an-example-post/?color=red. Notice the index.php in the middle? That's the key bit to making all this work.

Save the following code in a file called rewrite.script and upload it to your web space. Note that you will need to uncomment some parts of the script depending on whether your blog is in a sub directory or the top level of your site.

The code is currently set to work with a sub directory of blog. It has only been tested on Namesco servers and it's set to ignore their specific hosting folders like webmail, controlpanel and tech_support.

CODE:
  1. RULE_0_START:
  2. # Get the document root path and put value into the SCRATCH array.
  3. # This is the server path not the web URL.
  4. # e.g. /content/DesignerPlus/i/n/domain.co.uk/web/
  5. map path into SCRATCH:DOCROOT from /
  6.  
  7. # Get the URL without the domain.
  8. # e.g. /test&colour=red
  9. # e.g. /blog/2007/10/31/an-example-post/?color=red
  10. set SCRATCH:ORIG_URL = %{URL}
  11. set SCRATCH:REQUEST_URI = %{URL}
  12.  
  13. # See if there are any queries in our URL.
  14. match URL into $ with ^(.*)\?(.*)$
  15. # If there are...
  16. if matched then
  17.     # Set a var to path without the domain part.
  18.     # e.g. /blog/2007/10/31/an-example-post
  19.     set SCRATCH:REQUEST_URI = $1
  20.     # Set a var to the passed queries.
  21.     # e.g. colour=red
  22.     set SCRATCH:QUERY_STRING = $2
  23. endif
  24. RULE_0_END:
  25.  
  26. RULE_1_START:
  27. # This is setting a var to the server path and sub folders.
  28. # e.g. /content/DesignerPlus/i/n/domain.co.uk/web//blog/2007/10/31/an-example-post
  29. set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
  30. set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}
  31.  
  32. # Check to see if the file exists.
  33. look for file at %{SCRATCH:REQUEST_FILENAME}
  34. if not exists then
  35.     # The file wasn't found so is it a folder?
  36.     look for dir at %{SCRATCH:REQUEST_FILENAME}
  37.     if not exists then
  38.         # No folder either. So now check the URL for special hosting folders.
  39.         match SCRATCH:ORIG_URL into % with ^/webmail|^/tech_support|^/controlpanel
  40.         if matched then
  41.             # If a special folder was requested end the script.
  42.             goto END
  43.         else
  44.             # There were no files, folders or special folders so set the new URL.
  45.  
  46. # -- Sub directory -------------------------------------------------------------
  47.             # If the blog is in a sub directory...
  48.             # e.g. /blog/index.php/2007/10/31/an-example-post
  49.             match SCRATCH:REQUEST_URI into $ with ^/blog(.*)
  50.             if matched then
  51.                 set URL = /blog/index.php$1
  52.             endif
  53. # -- Sub directory ends --------------------------------------------------------
  54.  
  55. # or...
  56.  
  57. # -- Top level -----------------------------------------------------------------
  58.             # If the blog is in the top level of the site...
  59.             # e.g. /index.php/2007/10/31/an-example-post
  60. #            set URL = /index.php%{SCRATCH:REQUEST_URI}
  61. # -- Top level ends ------------------------------------------------------------
  62.            
  63.             # Go to the next rule.
  64.             goto RULE_2_START
  65.         endif
  66.     endif
  67. endif
  68. # If files or folders were found end the rewrite script.
  69. goto END
  70. RULE_1_END:
  71.  
  72. RULE_2_START:
  73. # Check for queries in the requested URL.
  74. match SCRATCH:ORIG_URL into % with \?(.*)$
  75. if matched then
  76.     # If queries were found add them to the new URL.
  77.     # e.g. /index.php/2007/10/31/an-example-post/&colour=red
  78.     set URL = %{URL}&%{SCRATCH:QUERY_STRING}
  79. endif
  80.  
  81. # -- Sub directory -------------------------------------------------------------
  82. # If you only want to rewrite the sub directory uncomment this bit.
  83. match SCRATCH:ORIG_URL into % with ^/blog
  84. if matched then
  85. # -- Sub directory ends --------------------------------------------------------
  86.    
  87.     # End the script.
  88.     goto END
  89.    
  90. # -- Sub directory -------------------------------------------------------------
  91. endif
  92. # -- Sub directory ends --------------------------------------------------------
  93. RULE_2_END:

4 Responses to “How to setup SEO friendly URLs for WordPress on Zeus”

  1. <a href='http://johnmccollum.co.uk' rel='external nofollow'>John McCollum</a> On December 4th, 2008 at 12:26 am , John McCollum wrote:

    Hi, I just wanted to say thanks for posting this. There seem to be very few examples of Zeus rewrite anywhere! I’m still some way off getting Zeus to do what I want, but this is a great example for me to study. Thanks again.

  2. <a href='http://www.realisingdesigns.com' rel='external nofollow'>James</a> On December 17th, 2008 at 6:45 pm , James wrote:

    Great article and exactly what I needed. Anyone with Wordpress and Zeus will know how many headaches it can cause. Thanks for the post.

  3. <a href='http://www.neuber-web-solutions.de' rel='external nofollow'>Andy</a> On January 3rd, 2009 at 9:07 am , Andy wrote:

    Thanks a lot for publishing this! In case I have to add another rule to this: In what script language is this written? Unix?

  4. Di On January 4th, 2009 at 12:45 am , Di wrote:

    It’s written in the Zeus Rewrite script language. You can find out more about it in the Zeus manual, specifically in chapter 8.7 Configuring Request Rewrite Scripts.

Leave a Reply

(will not be published)