Zeus redirection can often confuse people as it looks far more complicated than mod_rewrite under Apache. Below I've included some examples of common rewrites that you may find useful. All of these examples just need to be placed into a file named rewrite.script at the root of your website (where the index file is).
Redirect to a Different Website
If you want to redirect one website to another on the Zeus Web Server platform, simply use the following code :
insensitive match URL into $ with ^/(.*)
if matched then
set OUT:Location = http://www.othersite.com
set RESPONSE=301
set BODY=$1
goto END
endif
Replacing "www.othersite.com" with the website that you would like the redirect to push people through to.
Redirect from non-WWW to WWW
If you would like visitors to your site to be redirected from http://mysite.com to http://www.mysite.com this is the code you will need to use. Also you can do the opposite here, redirecting people from the www version of your site to the non-www version by adding www\. to the first mention of mysite.com and removing the www. from the second mention of mysite.com.
match IN:Host into $ with ^mysite\.com$
if matched then
match URL into $ with ^/(.*)$
set OUT:Location = http://www.mysite.com/$1
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif
All you need to do then is replace mysite.com (both instances) with your own domain name.
Redirect From One File to Another
If you would like to redirect people from one file (i.e. because it doesn't exist anymore) to another then you can use the example below, replacing the two example filenames with your own filenames.
insensitive match URL into $ with ^/oldfile\.html
if matched then
set OUT:Location = http://www.mysite.com/newfile.php
set RESPONSE=301
set BODY=$1
goto END
endif
Here you need to replace /oldfile\.html with the location you would like people redirected from (remembering to put a \ in front of all periods) and replacing http://www.mysite.com/newfile.php with the location you would like people taken to.
Sunny ~
Posted on 2011-09-02 06:47:59
Hi,
Thanks for your post. Can you please tell me how I can redirect from mydomain.com.au/index.php to the mydomain.com.au of my website?
Thanks for your help,
Sunny
You will need to replace all internal links on your site that currently use "mydomain.com.au/index.php" (or just index.php) and change them to "mydomain.com.au" (or "/"). If you try and use some sort of rule to redirect index.php to the main site then you'll just create a loop because they are technically the same page (that's assuming index.php is actually your index page).
Most search engines have a "Delist Page" request section you can use if after a while they are still listing "mysite.com/index.php" rather than just "mysite.com". But unless you actually have links on your site that reference "index.php" specifically it should just die off naturally.
Hi, do you know if there is a limit on the number of redirects you can have as I am using this script and after 30 it fails my script and nothing works, remove an entry and all is fine?
Any ideas
@Roger If you are on the Namesco platform (one of the few hosts that use Zeus) they put a limit on the number of redirects.
Michael ~
Posted on 2013-07-08 16:56:23
Hi, I am trying to get the www to non www redirect to work but it doesn't seem to be doing it. I am also on Namesco platform and I'm using the following script
match IN:Host into $ with ^www\.slyfilters\.com$
if matched then
match URL into $ with ^/(.*)$
set OUT:Location = http://slyfilters.com/$1
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif
Have I got anything wrong in there? I save the code in to a file called 'rewrite.script' and uploaded to the root of the site where the index file is.
Thanks in advance.
Michael ~
Posted on 2013-07-08 19:30:40
Obviously that smiley icon isn't part of the actual code and just got converted when pasting the code in to the comment box.
Michael ~
Posted on 2013-07-09 14:15:45
I have this figured out now by using the following code
## 301 Redirects
## Domain Check
insensitive match IN:Host into $ with ^www\.slyfilters\.com$
if matched
insensitive match URL into $ with ^/(.*)$
if matched
set OUT:Location = http: / /slyfilters.com/$1
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif
endif
(please note that I have spaced out the colon and slashes before the domain to avoid the code being converted to a smiley icon in this comment box)
Credit given to http://seo-website-designer.com/Zeus-Server-301-Redirect-Generator from where I was able to generate the correct code.
Hi Michael, so just to confirm, the differences were adding "insensitive" (which shouldn't really matter here but doesn't hurt) and adding in another "if matched" section? I didn't notice any other changes.
Michael ~
Posted on 2013-07-29 03:56:07
Yes, that seems to be the only difference that I can see.
Simon ~
Posted on 2013-10-11 17:13:11
Hi, how can I use the 301 redirect to
www.oldsite.com/some/crazy/link.html
to go to
www.newsite.com/some/crazy/link.html
The script at the top of the page redirects
www.oldsite.com/some/crazy/link.html
to go to
www.newsite.com
but I'd like it to retain the address after the / so it redirects to the page requested.
Is this possible?
Anthony ~
Posted on 2014-01-21 14:30:52
Hi,
I am redirecting pages from our old site to our new one (same domain). Using the script above, we got the first redirect below to work... but oddly none of the others worked. See below...
1st redirect worked...
insensitive match URL into $ with ^/my_lady.\html if matched then set OUT:Location = http://fairytalebridesltd.co.uk/index.php/wedding_dresses/my_lady/ set RESPONSE=301 set BODY=$1 goto END endif
subsequent redirects didnt...
insensitive match URL into $ with ^/contact\.php if matched then set OUT:Location = http://www.fairytalebridesltd.co.uk/index.php/contact-us/ set RESPONSE=301 set BODY=$1 goto END endif
Any idea why?
Assuming I'm remembering correctly (haven't done Zeus rewrites for a while) "goto END" means go to the end of the file, so it'll skip all subsequent lines in the rewrite.script. Leave out the "goto END" entries if you have multiple rules.
Anthony ~
Posted on 2014-01-21 16:21:32
HI, Thanks for the fast response
I have tried removing the "goto END" but am still not seeing redirects on anything but the first submission. My first three now look like...
insensitive match URL into $ with ^/my_lady.\html
if matched then
set OUT:Location = http://fairytalebridesltd.co.uk/index.php/wedding_dresses/my_lady/
set RESPONSE=301
set BODY=$1
endif
insensitive match URL into $ with ^/contact.\php
if matched then
set OUT:Location = http://fairytalebridesltd.co.uk/index.php/contact-us/
set RESPONSE=301
set BODY=$1
endif
insensitive match URL into $ with ^/faq\.php
if matched then
set OUT:Location = http://fairytalebridesltd.co.uk/index.php/about_us/
set RESPONSE=301
set BODY=$1
endif
I have even tried removing the 'end if' to no avail :/
Clive ~
Posted on 2014-01-23 09:08:32
My Namesco-based site is being spammed with lots of hits from different IPs, but all with the same referer. How would I use rewrite.script to redirect these annoyances?
Patrick ~
Posted on 2014-05-07 15:25:02
Can I ask about a redirect here? I have one that redirects depending on whether user is on a mobile or not and it works but now the main site has garbage on the front page. Sorry in advance if I'm jumping in where I don't belong. If I am please steer me in the right direction. Do I start a new post?
Are you using a rewrite.script to do that? If so, what is the code you're using?
Patrick ~
Posted on 2014-05-07 15:27:49
Wow - wasn't expecting an instant reply. Redirect is fine but main site is now looks odd.
### Built using the Zeus Server 301 Redirect Script Generator from Web Site Advantage
### http://seo-website-designer.com/Zeus-Server-301-Redirect-Generator
## 301 Redirects
# 301 Redirect 1
insensitive match URL into $ with ^/$
if matched
map path into SCRATCH:DOCROOT from /
match IN:User-Agent into $ with iPad|iPod|iPhone|Android|s+Mobile
if matched then
match IN:Host into % with ^(.*)$
set OUT:Location = http://m.WEBSITE.ie/
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif
endif
Patrick ~
Posted on 2014-05-07 15:29:23
Forgot - The website is shanai.ie
You've got PHP code in your HTML section. If you bring up the source for the page you can see that you've put the actual PHP code in the page, perhaps within an existing PHP echo section. Shouldn't be related to the Zeus script.
Check the actual PHP source as you seem to have some critical error in there.
Patrick ~
Posted on 2014-05-07 15:37:02
I have that in the rewrite.script file, isn't that where it's supposed to be? I don't really have access to the rest of the site files - I was just asked to supply some redirect code in the rewrite.script file.
The code you've pasted on here looks fine. The code you're seeing on the website shouldn't (and couldn't) really be related, considering it's printing out PHP code.
Patrick ~
Posted on 2014-05-07 15:41:19
Gotcha - and I agree - problem is this PHP code only appeared when I added the rewrite.script file. It's not my site and as far as they're concerned this problem only started when I did the rewrite.
Patrick ~
Posted on 2014-05-07 15:51:06
Hi Benjamin - I was just granted more access to the site and I noticed that this PHP code is at the very beginning of the index.html file - no idea how it got there but more proof that it's not my rewrite. At least I know my rewrite is good - first time doing anything like this.
Sarah ~
Posted on 2015-02-11 14:42:16
Hi Guys,
I am trying to create a rewrite.script that redirects people from the http:// to https:// so they are on our secure site. I have looked everywhere and can't seem to find anything.
Any help would be great
sarah ~
Posted on 2015-06-17 10:04:01
Hi
Thanks for the blog really useful, I was hoping you would be able to help. I currently have a rewrite.script redirect non www. to www. which works great. However i now need to direct the http:// site to the secure https:// and struggling to do this any advice would be great.
Hi Sarah, try this at the top of your rewrite.script:
http.changeSite("https://".http.getHostHeader());
Sarah ~
Posted on 2015-07-24 09:55:19
Hi Benjamin,
Thank you for your comment unfortunately this didn't work -
This is the code i have placed in the rewrite, the non www. works but not the https://
Any help would be much appreciated.
http.changeSite("https://".http.getHostHeader());
match IN:Host into $ with ^***\.co\.uk$
if matched
match URL into $ with ^/(.*)$
if matched
set OUT:Location = http://www.***.co.uk/$1
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
endif
endif
Post a Comment