如何在 Zeus Web 服务器中为移动用户代理重写 URL? [英] How can I rewrite URLs in the Zeus web server for Mobile useragent?

查看:69
本文介绍了如何在 Zeus Web 服务器中为移动用户代理重写 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将任何拥有移动用户代理的人重定向到一个名为 mobile.php 的文件.我的网络托管服务提供商 Net Registry 使用 Zeus 网络服务器.

I need to redirect anyone with a mobile user agent to a file called mobile.php. My web hosting provider, Net Registry uses the Zeus web server.

这是我从研究中编写的脚本

Here's the script I've written from my research

RULE_1_START:
# get the document root
map path into SCRATCH:DOCROOT from /
match IN:User-Agent into $ with iPad|iPod|iPhone|Android|s+Mobile

if matched then
    set OUT:Location = /mobile.php
endif
RULE_1_END:

我使用了主机网站上的说明.

我将其粘贴到他们的控制台中,并且可以进行重定向.Net 注册表中有一些您提交的奇怪控制台内容,更新 zeus 服务器配置需要 10 分钟(烦死了).

I pasted that into their console and it has worked to do redirects. Net registry have some odd console thing that you submit and it takes 10 minutes to update the zeus server config (annoying as hell).

无论如何,我的问题是它将我重定向到错误的位置:因此,如果您使用包含 ipad|ipod|android|\s+mobile 的用户代理字符串访问该站点,那么您将触发它 ()

Anyway my issue is that it redirects me to the wrong location: So if you visit the site, with a user agent string that contains ipad|ipod|android|\s+mobile then you will trigger it ()

它带我到这里:

http://example.com.au/mobile.php,%20catalog/index.php

我不知道如何解决这个问题,或者为什么会发生这种情况,因为目前这个文件存在:

I can't work out how to fix that, or why that happens because at the moment this file exists:

http://example.com.au/mobile.php

就像这个:

http://example.com.au/index.php. Contents of this file are:

<?php header("Location: catalog/index.php");

关于如何使这项工作更像 apache .htaccess url Rewrite 的任何想法?

Any ideas on how I can make this work more like an apache .htaccess url Rewrite?

Zeus 官方文档

推荐答案

通过更改修复

   set OUT:Location = /mobile.php

   set URL = /mobile.php

从手册...使用请求重写脚本要使用请求重写功能,请在 Zeus 请求中创建一个脚本重写脚本语言.该脚本包含的说明告诉虚拟服务器如何更改与指定条件匹配的请求的 URL 或标头.虚拟服务器编译脚本,并且(如果重写功能是启用)每次收到请求时都会使用它.它运行命令脚本,如果 URL 匹配指定的条件,则更改 URL.一旦脚本完成后,虚拟服务器将继续处理生成的 URL.Zeus Web Server 4.3 用户指南142 配置URL处理更改 URL 时,重写功能只能更改本地它的一部分,即主机名后面的 URL 部分.例如,如果一个用户请求 http://www.myhost.com/sales/uk.html,改写功能只能对/sales/uk.html 进行更改.这意味着您不能使用重写功能将请求更改为引用另一个虚拟服务器上的文件.例如,以下脚本说明了如何更改任何请求/sales 目录中的 HTML 文件,以便用户从/newsales 目录:将 URL 与 ^/sales/(.).html 匹配到 $如果匹配设置 URL=/newsales/$1.html重写功能还可以更改收到的 HTTP 标头使用请求,并创建要返回给用户的新 HTTP 标头.为了例如,以下脚本更改 HTTP 主机标头,以便请求对于 www.mysite.com/subserver 被重定向到子服务器www.subserver.mysite.com:将 URL 与 ^/([^/]+)/(.)$ 匹配到 $如果匹配则设置 IN:Host = www.$1.mysite.com设置 URL =/$2结束

From the manual... Using Request Rewrite Scripts To use the request rewriting functionality, create a script in the Zeus Request Rewrite Scripting Language. The script contains instructions telling the Virtual Server how to change the URL or headers of requests that match specified criteria. The Virtual Server compiles the script, and (if the rewrite functionality is enabled) uses it every time it receives a request. It runs the commands in the script, changing the URL if it matches the specified criteria. Once the script is finished, the Virtual Server continues processing the resulting URL.Zeus Web Server 4.3 User Guide 142 Configuring URL Handling When changing the URL, the rewrite functionality can only change the local part of it, that is, the part of the URL after the host name. For example, if a user requests http://www.myhost.com/sales/uk.html, the rewrite functionality can only make changes to /sales/uk.html. This means that you cannot use the rewrite functionality to change the request to refer to a file on another Virtual Server. 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: match URL into $ with ^/sales/(.).html if matched set URL=/newsales/$1.html The rewrite functionality can also change the HTTP headers that were received with a request, and create new HTTP headers to be returned to the user. For example, the following script changes the HTTP host header, so that a request for www.mysite.com/subserver is redirected to the Subserver www.subserver.mysite.com: match URL into $ with ^/([^/]+)/(.)$ if matched then set IN:Host = www.$1.mysite.com set URL = /$2 endif

这篇关于如何在 Zeus Web 服务器中为移动用户代理重写 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆