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.
#1 by Jules Gravinese on January 23, 2009 - 4:20 am
Quote
Gee… considering only the lengths, it reminds me of a code comparison of PHP vs ColdFusion!
#2 by Ivan | Jobs Blog on April 1, 2009 - 9:28 am
Quote
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 by Anuj Gakhar on April 2, 2009 - 9:23 am
Quote
@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 by Ivan | Jobs Blog on April 2, 2009 - 9:50 am
Quote
@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 by Anuj Gakhar on April 2, 2009 - 10:04 am
Quote
@Ivan, Glad you got it sorted. Would you mind sharing your solution here?
#6 by Alp on April 7, 2009 - 4:30 pm
Quote
Ivan, would be great if you shared your script for two WordPress installations. Many thanks
#7 by Ivan | Jobs Blog on April 16, 2009 - 3:32 pm
Quote
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 by Anuj Gakhar on April 23, 2009 - 12:13 pm
Quote
@Ivan, thanks for posting that here. Much appreciated.
Pingback: ゆっくりと… » LaCoocanの.htaccessで出来ること
#9 by Jauhm Jaumas on August 6, 2010 - 1:25 pm
Quote
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