WordPress .htaccess on Zeus

On January 23, 2009, in Web Development, Miscellaneous, by Anuj Gakhar

I normally don’t take up such tasks, but I was recently tasked to migrate an old WordPress installation to a new server and a new version. This sounded like a pretty simple task to do, so I took it up. Upload the files, export data from the old one, import into new one and thats it! Well, thats what I thought until I found out that the new server was not running Apache. Instead, it was running Zeus webserver. WordPress uses .htaccess (mod_rewrite module) to build pretty looking URL’s (without the index.php in the URL) and unfortunately, just copying the Apache .htacess to a Zeus webserver won’t work. Took me over an hour to figure that out!

Finally, after a while of googling about this, the .htacess that looks like this :-


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

now looks like this on Zeus webserver(the file should be called rewrite.script and placed on the root of your web just like .htaccess)


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
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:

I must say that is a lot of code in comparison to .htacess. This is the URL I found this info on.

Finally, I got this working and all is well that ends well.

 

20 Responses to WordPress .htaccess on Zeus

  1. Gee… considering only the lengths, it reminds me of a code comparison of PHP vs ColdFusion!

  2. I got the blog running OK in the root of hte domain on Zeus. But what do you do when you have it running in the directory? One would guess replicate this all include the rewrite.script in the directory. And it works fine like that as well.

    But my problem is that I have a web site that is actually WordPress in the root, and then another wordpress in the /blog/ directory. The problem is that the rewrite-ing rules from the root take over and none of those dynamic links in the WP that is in the subdirectory work, but I actually get a 404 from the wp in the root.

    So is there a way to exclude a path from the rewrite.script, so that it does not do nothing for a url’s that are in the /blog/ folder? Or can I do that in the .htaccess somehow?

  3. Anuj Gakhar says:

    @Ivan, Sorry, cant be of much help here as I havent worked much with Zeus myself. Probably http://drupal.org/node/46508 this might give you some headstarts ?

  4. @Anuj – Thanks for a note! I got it sorted. A bit of Google-ing and one learns how to program in the Zeus scripting language in no time! 🙂

  5. Anuj Gakhar says:

    @Ivan, Glad you got it sorted. Would you mind sharing your solution here?

  6. Alp says:

    Ivan, would be great if you shared your script for two WordPress installations. Many thanks 🙂

  7. RULE_0_START:
    # Get the document root path and put value into the SCRATCH array.
    # This is the server path not the web URL.
    # e.g. /content/DesignerPlus/i/n/domain.co.uk/web/
    map path into SCRATCH:DOCROOT from /

    # Get the URL without the domain.
    # e.g. /test&colour=red
    # e.g. /blog/2007/10/31/an-example-post/?color=red
    set SCRATCH:ORIG_URL = %{URL}
    set SCRATCH:REQUEST_URI = %{URL}

    # See if there are any queries in our URL.
    match URL into $ with ^(.*)\?(.*)$
    # If there are…
    if matched then
    # Set a var to path without the domain part.
    # e.g. /blog/2007/10/31/an-example-post
    set SCRATCH:REQUEST_URI = $1
    # Set a var to the passed queries.
    # e.g. colour=red
    set SCRATCH:QUERY_STRING = $2
    endif
    RULE_0_END:

    RULE_1_START:
    # This is setting a var to the server path and sub folders.
    # e.g. /content/DesignerPlus/i/n/domain.co.uk/web//blog/2007/10/31/an-example-post
    set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
    set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

    # Check to see if the file exists.
    look for file at %{SCRATCH:REQUEST_FILENAME}
    if not exists then
    # The file wasn’t found so is it a folder?
    look for dir at %{SCRATCH:REQUEST_FILENAME}
    if not exists then
    # No folder either. So now check the URL for special hosting folders.
    match SCRATCH:ORIG_URL into % with ^/webmail|^/tech_support|^/controlpanel
    if matched then
    # If a special folder was requested end the script.
    goto END
    else
    # There were no files, folders or special folders so set the new URL.

    # — Sub directory ————————————————————-
    # If the blog is in a sub directory…
    # e.g. /blog/index.php/2007/10/31/an-example-post
    match SCRATCH:REQUEST_URI into $ with ^/blog(.*)
    if matched then
    set URL = /blog/index.php$1
    # — Top level —————————————————————–
    # If the blog is in the top level of the site…
    # e.g. /index.php/2007/10/31/an-example-post
    else
    set URL = /index.php%{SCRATCH:REQUEST_URI}
    # If there is only a top level blog you can remove the
    # match and surrounding if statements.
    endif
    # — —————————————————————————

    # Go to the next rule.
    goto RULE_2_START
    endif
    endif
    endif
    # If files or folders were found end the rewrite script.
    goto END
    RULE_1_END:

    RULE_2_START:
    # Check for queries in the requested URL.
    match SCRATCH:ORIG_URL into % with \?(.*)$
    if matched then
    # If queries were found add them to the new URL.
    # e.g. /index.php/2007/10/31/an-example-post/&colour=red
    set URL = %{URL}&%{SCRATCH:QUERY_STRING}
    endif

    # — Sub directory ————————————————————-
    # If you only want to rewrite the sub directory uncomment this bit.
    match SCRATCH:ORIG_URL into % with ^/blog
    if matched then
    # — Sub directory ends ——————————————————–

    # End the script.
    goto END

    # — Sub directory ————————————————————-
    endif
    # — Sub directory ends ——————————————————–
    RULE_2_END:

  8. Anuj Gakhar says:

    @Ivan, thanks for posting that here. Much appreciated.

  9. Jauhm Jaumas says:

    Merci, Je suis francais et j’ecris en francais. J’ai trouve cet article tres interessant, les article sont tres bien r�dige ! Bonne continuation. I like this

  10. Colin says:

    You have literally just saved me pulling my hair out. I have been stuck for about 4 hours trying to get permalinks to work.

    !!!Thankyou!!!

  11. ronanward says:

    Thanks for this, your a life saver!! I’ve been trying to solve this problem for over a week. Thanks again!

  12. Uday says:

    Hi!
    Thanks it really worked well. But only problem remains is that the url contains index.php in between. without that it does not work.
    Can you please let me know what can i do to remove index.php from url?
    Thanks once again.

  13. Uday says:

    Hi!
    just found out that rewrite.script is not working on my zeus server.
    when i removed that file still the things are working as they are working now.
    So is there anything needs to be enabled on the server. i mean the way we activate mod_rewrite on apache server??
    thanks once again
    uday

  14. Darren says:

    Many thanks for this info!
    Had to use Zeus hosting from a client.
    A lot of Zeus rewrite script code in comparison to apache mod_rewrite.

    Cheers,
    Darren.

  15. Pete says:

    Thanks, I’ve been searching for this for ages!

    Pete

  16. Jeremiah says:

    Hey, many thanks for the code. Worked a treat! 🙂

  17. Geri says:

    You legend! I’ve been tearing my hair out over this problem, nice fix.

  18. dexter says:

    Can anyone please tell me why i can’t get this to work?

    I have uploaded the rewrite.script in the root folder.

    I have change the permalinks settings.

    Still get 404 error.

    Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 446 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: