-
AppExpert Applications and Templates
-
Configure application authentication, authorization, and auditing
-
-
Advanced Policy Expressions: Working with Dates, Times, and Numbers
-
Advanced Policy Expressions: Parsing HTTP, TCP, and UDP Data
-
Advanced Policy Expressions: IP and MAC Addresses, Throughput, VLAN IDs
-
Tutorial Examples of Default Syntax Policies for Rewrite
-
-
This content has been machine translated dynamically.
Dieser Inhalt ist eine maschinelle Übersetzung, die dynamisch erstellt wurde. (Haftungsausschluss)
Cet article a été traduit automatiquement de manière dynamique. (Clause de non responsabilité)
Este artículo lo ha traducido una máquina de forma dinámica. (Aviso legal)
此内容已经过机器动态翻译。 放弃
このコンテンツは動的に機械翻訳されています。免責事項
이 콘텐츠는 동적으로 기계 번역되었습니다. 책임 부인
Este texto foi traduzido automaticamente. (Aviso legal)
Questo contenuto è stato tradotto dinamicamente con traduzione automatica.(Esclusione di responsabilità))
This article has been machine translated.
Dieser Artikel wurde maschinell übersetzt. (Haftungsausschluss)
Ce article a été traduit automatiquement. (Clause de non responsabilité)
Este artículo ha sido traducido automáticamente. (Aviso legal)
この記事は機械翻訳されています.免責事項
이 기사는 기계 번역되었습니다.책임 부인
Este artigo foi traduzido automaticamente.(Aviso legal)
这篇文章已经过机器翻译.放弃
Questo articolo è stato tradotto automaticamente.(Esclusione di responsabilità))
Translation failed!
Tutorial examples of default syntax policies for rewrite
With the rewrite feature, you can modify any part of an HTTP header, and, for responses, you can modify the HTTP body. You can use this feature to accomplish several useful tasks, such as removing unnecessary HTTP headers, masking internal URLs, redirecting webpages, and redirecting queries or keywords.
In the following examples, you first create a rewrite action and a rewrite policy. Then you bind the policy globally.
This document includes the following details:
- Redirecting an External URL to an Internal URL
- Redirecting a Query
- Rewriting HTTP to HTTPS
- Removing Unwanted Headers
- Reducing Web Server Redirects
- Masking the Server Header
- Converting plain text to URL encoded string and the opposite way
For more information about the commands and syntax descriptions, see Rewrite Command Reference page.
Redirecting an external URL to an internal URL
This example describes how to create a rewrite action and rewrite policy that redirects an external URL to an internal URL. You create an action, called act_external_to_internal, that performs the rewrite. Then you create a policy called pol_external_to_internal.
To redirect an external URL to an internal URL by using the CLI
- To create the rewrite action, at the command prompt, type:
add rewrite action act_external_to_internal REPLACE “http.req.hostname.server” “\”host_name_of_internal_Web_server\””
- To create the rewrite policy, at the Citrix ADC command prompt, type:
add rewrite policy pol_external_to_internal "http.req.hostname.server.eq(\"host_name_of_external_Web_server\")" act_external_to_internal
- Bind the policy globally.
To redirect an external URL to an internal URL by using the configuration utility
- Navigate to AppExpert > Rewrite > Actions.
- In the details pane, click Add.
- In the Create Rewrite Action dialog box, enter the name act_external_to_internal.
- To replace the HTTP server host name with the internal server name, choose Replace from the Type list box.
- In the header name field, type Host.
- In the string expression for a replacement text field, type the internal host name of your Web server.
- Click Create and then click Close.
- In the navigation pane, click Policies.
- In the details pane, click Add.
- In the Name field, type pol_external_to_internal. This policy detects connections to the Web server.
- In the Action drop-down menu, choose the action act_external_to_internal.
- In the Expression editor, construct the following expression:
HTTP.REQ.HOSTNAME.SERVER.EQ("www.example.com")
<!--NeedCopy-->
- Bind your new policy globally.
Redirecting a query
This example describes how to create a rewrite action and rewrite policy that redirects a query to the proper URL. The example assumes that the request contains a Host header set to www.example.com and a GET method with the string /query.cgi?server=5. The redirect extracts the domain name from the host header and the number from the query string, and redirects the user’s query to the server Web5.example.com, where the rest of the user’s query is processed.
Note:
Although the following commands appear on multiple lines, you must enter them on a single line without line breaks.
To redirect a query to the appropriate URL using the CLI
- To create a rewrite action named act_redirect_query that replaces the HTTP server host name with the internal server name, type:
add rewrite action act_redirect_query REPLACE http.req.header("Host").before_str(".example.com") '"Web" + http.req.url.query.value("server")'
- To create a rewrite policy named pol_redirect_query, type the following commands at the Citrix ADC command prompt. This policy detects connections, to the Web server, that contain a query string. Do not apply this policy to connections that do not contain a query string:
add rewrite policy pol_redirect_query 'http.req.header("Host").eq(www.example.com) && http.req.url.contains("?")' act_redirect_query
- Bind your new policy globally.
Because this rewrite policy is highly specific and must be run before any other rewrite policies, it is advisable to assign it a high priority. If you assign it a priority of 1, it is evaluated first.
Rewriting HTTP to HTTPS
This example describes how to rewrite Web server responses to find all URLs that begin with the string “HTTP” and replace that string with “https.” You can use it to avoid having to update webpages after moving a server from HTTP to HTTPS.
To redirect HTTP URLs to HTTPS by using the CLI
- To create a rewrite action named act_replace_http_with_https that replaces all instances of the string “HTTP” with the string “https,” enter the following command:
add rewrite action act_replace_http_with_https replace_all 'http.res.body(100)' '"https"' -pattern http
- To create a rewrite policy named pol_replace_http_with_https that detects connections to the Web server, enter the following command:
add rewrite policy pol_replace_http_with_https TRUE act_replace_http_with_https NOREWRITE
- Bind your new policy globally.
To troubleshoot this rewrite operation, see “Case Study: Rewrite Policy for Converting HTTP Links to HTTPS not Working.”
Removing Unwanted Headers
This example explains how to use a Rewrite policy to remove unwanted headers. Specifically, the example shows how to remove the following headers:
- Accept Encoding header. Removing the Accept Encoding header from HTTP responses prevents compression of the response.
- Content Location header. Removing the Content Location header from HTTP responses prevents your server from providing a hacker with information that might allow a security breach.
To delete headers from HTTP responses, you create a rewrite action and a rewrite policy, and you bind the policy globally.
To create the appropriate Rewrite action by using the CLI
At the command prompt, type one of the following commands to either remove the Accept Encoding header and prevent response compression or remove the Content Location header:
add rewrite action "act_remove-ae" delete_http_header "Accept-Encoding"
add rewrite action "act_remove-cl" delete_http_header "Content-Location"
To create the appropriate Rewrite policy by using the CLI
At the command prompt, type one of the following commands to remove either the Accept Encoding header or the Content Location header:
add rewrite policy "pol_remove-ae" true "act_remove-ae"
add rewrite policy "pol_remove-cl" true "act_remove-cl"
To bind the policy globally by using the CLI
At the command prompt, type one of the following commands, as appropriate, to globally bind the policy that you have created:
bind rewrite global pol_remove_ae 100
bind rewrite global pol_remove_cl 200
Reducing Web Server Redirects
This example explains how to use a Rewrite policy to modify connections to your home page and other URLs that end with a forward slash (/) to the default index page for your server, preventing redirects and reducing load on your server.
To modify directory-level HTTP requests to include the default home page by using the CLI
- To create a Rewrite action named action-default-homepage that modifies URLs that end in a forward slash to include the default home page index.html, type:
add rewrite action "action-default-homepage" replace http.req.url.path "\"/index.html\""
- To create a Rewrite policy named policy-default-homepage that detects connections to your home page and applies your new action, type:
add rewrite policy "policy-default-homepage" q\#http.req.url.path.EQ("/") "action-default-homepage"\#
- Globally bind your new policy to put it into effect.
Masking the Server Header
This example explains how to use a Rewrite policy to mask the information in the Server header in HTTP responses from your Web server. That header contains information that hackers can use to compromise your website. While masking the header will not prevent a skilled hacker from finding out information about your server, it makes hacking your Web server more difficult and encourage hackers to choose less well protected targets.
To mask the Server header in responses from the CLI
- To create a Rewrite action named act_mask-server that replaces the contents of the Server header with an uninformative string, type:
add rewrite action "act_mask-server" replace "http.RES.HEADER(\"Server\")" "\"Web Server 1.0\""
- To create a Rewrite policy named pol_mask-server that detects all connections, type:
add rewrite policy "pol_mask-server" true "act_mask-server"
- Globally bind your new policy to put it into effect.
How to convert plain text to URL encoded string and the opposite way
The following expressions convert plain text to URL encoded string and the opposite way:
- URL_RESERVED_CHARS_SAFE (string to URL ENCODED).
Example:
("abc def&123").URL_RESERVED_CHARS_SAFE
Output will be
“abc%20def%26123” which is url encoded.
<!--NeedCopy-->
- SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE. (URL ENCODED to string)
Example:
("abc%20def%26123").SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE
Output will be
“abc def&123”
<!--NeedCopy-->
Share
Share
This Preview product documentation is Cloud Software Group Confidential.
You agree to hold this documentation confidential pursuant to the terms of your Cloud Software Group Beta/Tech Preview Agreement.
The development, release and timing of any features or functionality described in the Preview documentation remains at our sole discretion and are subject to change without notice or consultation.
The documentation is for informational purposes only and is not a commitment, promise or legal obligation to deliver any material, code or functionality and should not be relied upon in making Cloud Software Group product purchase decisions.
If you do not agree, select I DO NOT AGREE to exit.