📄 rewrite-tags.xtp
字号:
<!-- server/13n8.qa --><example title="Merge path: replacing some images with custom images"><web-app xmlns="http://caucho.com/ns/resin"> <rewrite-real-path> <real-path regexp="^/images" target="merge:(custom-images;images)"/> </rewrite-real-path></example><!-- server/13n9.qa --><example title="Merge path: managing the versioning and customization of a php application"><web-app xmlns="http://caucho.com/ns/resin"> <rewrite-real-path> <real-path regexp="^/" target="merge:(WEB-INF/SugarCE-local;WEB-INF/SugarCE-Full-5.0.0a)"/> </rewrite-real-path></example></s2></defun><defun title="<rewrite-dispatch>"><parents>server, host, web-app</parents><p><rewrite-dispatch> evaluates the child tags in order. The firstmatching tag dispatches the request. If no children match, the requestuses the standard servlet handling.</p><p>The child tags rewrite and dispatch based on regexp patterns.</p><example title="Mediawiki dispatch in resin-web.xml"><web-app xmlns="http://caucho.com/ns/resin"> <rewrite-dispatch> <dispatch regexp="\.(php|gif|css|jpg|png)"/> <forward regexp="^" target="/index.php"/> </rewrite-dispatch></web-app></example><deftable-childtags><tr><td><a href="#dispatch"><dispatch></a></td> <td>Dispatch the request immediately and do not process any more rules</td> <td></td></tr><tr><td><a href="#forbidden"><forbidden></a></td> <td>Send a 403 Forbidden response to browser and do not process any more rules</td> <td></td></tr><tr><td><a href="#forward"><forward></a></td> <td>Rewrite the URL and internally forward the request without processing any more rules</td> <td></td></tr><tr><td><a href="#forbidden"><forbidden></a></td> <td>Send a 410 Gone response to the browser and do not process any more rules</td> <td></td></tr><tr><td><a href="#import"><import></a></td> <td>Import rules from an external file</td> <td></td></tr><tr><td><a href="#load-balance"><load-balance></a></td> <td>Forward requests to another instance or instances of Resin and do not process any more rules</td> <td></td></tr><tr><td><a href="#match"><match></a></td> <td>Group more specific rules</td> <td></td></tr><tr><td><a href="#moved-permanently"><moved-permanently></a></td> <td>Send a 310 Moved Permanently response to the browser and do not process any more rules</td> <td></td></tr><tr><td><a href="#redirect"><redirect></a></td> <td>Send a 302 Moved response to the browser and do not process any more rules</td> <td></td></tr><tr><td><a href="#rewrite"><rewrite></a></td> <td>Rewrite the current URL and continue processing rules</td> <td></td></tr><tr><td><a href="#set"><set></a></td> <td>Set a property of the request or response and continue processing rules</td> <td></td></tr></deftable-childtags></defun><defun title="secure"><parents>when, unless</parents><p><secure> specifies a condition for the ssl status of the request. If <var/secure/> is true,then the request must be using ssl for the rule to match. If <var/secure/> isfalse, then the request must not be using ssl for the rule to match. If<var/secure/> is not specified, the ssl status of the request is not considered whentesting if the rule matches.</p><example title="secure example"><web-app xmlns="http://caucho.com/ns/resin"> <rewrite-dispatch> <redirect regexp='^/foo' target='/secure'> <when secure='true'/> </redirect> <redirect regexp='^/foo' target='/insecure'> <when secure='false'/> </redirect> <redirect regexp='^/bar' target='/public'/> </rewrite-dispatch></web-app></example><results>http://localhost:8080/foo/index.html --> redirect to /insecure/index.htmlhttps://localhost:8080/foo/index.html --> redirect to /secure/index.htmlhttp://localhost:8080/bar/index.html --> redirect to /public/index.htmlhttps://localhost:8080/bar/index.html --> redirect to /public/index.html</results></defun><defun title="server-name"><parents>when, unless</parents><p>Evaluates to true if the value of the request's server name matches the specifiedregexp, false if it does not. The comparison is always case insensitive.The server name is the name that the client has used to connect to the server and may not be the name of the actual server that is hosting Resin.</p><p>Most potential problems that can be solved by <code>server-name</code> aremore efficiently solved using <g>virtual hosts</g> and the<a href="host-tags.xtp#host">host-alias</a> tag.</p><deftable-childtags><tr><td>server-name</td> <td>A regular expression to match.</td> <td>required</td></tr></deftable-childtags></defun><defun title="server-port"><parents>when, unless</parents><p>Evaluates to true if the value of the request's server port is the specifiedvalue, false if it does not. The server port is the port that the client has used to connect to the server and may not be the actual port that Resin is bound to.</p><deftable-childtags><tr><td>server-port</td> <td>The server port to match.</td> <td>required</td></tr></deftable-childtags></defun><defun title="<set>"><parents>rewrite-dispatch, match</parents><p><set> is used to set properties of the request or response before continuing on to the next rule.The properties are maintained after the rewriting is complete, for example a request that becomes securebecause of <set> will continue to be regarded as secure when the request eventually reaches a jspor servlet.</p><example title="Making the request secure in response to a header from a hardware load balancer"><web-app xmlns="http://caucho.com/ns/resin"> <rewrite-dispatch> <set request-secure="true"> <when header="X-SSL-cipher"/> </set> <forward regexp="^/checkout" target="https://hogwarts.com/checkout"> <when secure="false"/> </forward> </rewrite-dispatch></web-app></example><deftable-childtags><tr><td><a href="#disable-at">disable-at</a></td> <td>A cron syntax time specification for triggering disablement of the rule</td> <td>none</td></tr><tr><td><a href="#enable-at">enable-at</a></td> <td>A cron syntax time specification for triggering enablement of the rule</td> <td>none</td></tr><tr><td>enabled</td> <td>False to start with the rule initially disabled</td> <td>true</td></tr><tr><td><a href="#name">name</a></td> <td>A name to use for registering a JMX mbean with type=RewriteRule</td> <td>do not register an mbean</td></tr><tr><td>regexp</td> <td>A regexp that must match the <a href="#URL">URL</a></td> <td>optional</td></tr><tr><td>request-character-encoding</td> <td>Sets the character encoding of the request, used for parsing POST data, request.setCharacterEncoding(value)</td> <td>none</td></tr><tr><td>request-secure</td> <td>Sets the value of request.isSecure()</td> <td>none</td></tr><tr><td>response-character-encoding</td> <td>Sets the value of the character encoding sent for the response with response.setCharacterEncoding(value). If a Content-Type is not set either with a set rule, or by some other process involved in servicing the request, this has no effect.</td> <td>none</td></tr><tr><td>response-content-type</td> <td>Sets the value of the content type sent for the response. If the final destination is a file with a corresponding <a href="webapp-tags.xtp#mime-mapping">mime-mapping</a>, the mime-mapping will override the content-type set here</td> <td>none</td></tr><tr><td><a href="#when">when</a></td> <td>A condition which must evaluate to true</td> <td>optional</td></tr><tr><td><a href="#unless">unless</a></td> <td>A condition which must not evaluate to true</td> <td>optional</td></tr></deftable-childtags></defun><defun title="<unless>"><p>Contains a condition that further refines the match of the enclosing tag beyondthe information provided by the url. If the condition does not evaluate totrue, then the enclosing tag is applied.</p><p>See <a href="#when"><when></a> for a description of possible conditions.</p></defun><defun title="user-in-role"><parents>when, unless</parents><p>Evaluates to true if the user is authenticated and in the specified role.The special role of '*' means any role.</p><p>If the current user is any role, a <code>Cache-Control</code> header containing"<code>private</code>" is added to the response.</p><deftable-childtags><tr><td>user-in-role</td> <td>A role name.</td> <td>required</td></tr><tr><td>send-vary</td> <td>Send a <code>Vary</code> header containing "<code>Cookie</code>" as part of the response</td> <td>true</td></tr></deftable-childtags></defun><defun title="<when>"><p>Contains a condition that further refines the match of the enclosing tag beyondthe information provided by the url. If the condition evaluates to true, thenthe enclosing tag is applied.</p><deftable-childtags><tr><td><a href="#and"><and></a></td> <td>A subgroup of conditions that must all pass</td> <td></td></tr><tr><td><a href="#auth-type">auth-type</a></td> <td>Evaluates to true if the authorization mechanism used in the request is the given value</td> <td></td></tr><tr><td><a href="#cookie">cookie</a></td> <td>Evaluates to true if a cookie exists and matches an optional <var/regexp/></td> <td></td></tr><tr><td><a href="#header">header</a></td> <td>Evaluates to true if a request header exists and matches an optional <var/regexp/></td> <td></td></tr><tr><td><a href="#locale">locale</a></td> <td>Evaluates to true if the request locale matches the specified value</td> <td></td></tr><tr><td><a href="#local-port">local-port</a></td> <td>Evaluates to true if the local port is the specified value (the local port is the actual port that Resin is using)</td> <td></td></tr><tr><td><a href="#method">method</a></td> <td>Evaluates to true if the http method used for the request is the specified value</td> <td></td></tr><tr><td><a href="#not"><not></a></td> <td>A subgroup of conditions, none of which may pass</td> <td></td></tr><tr><td><a href="#or"><or></a></td> <td>A subgroup of conditions, any of which may pass</td> <td></td></tr><tr><td><a href="#query-param">query-param</a></td> <td>Evaluates to true if a query parameter exists and matches an optional <var/regexp/></td> <td></td></tr><tr><td>regexp</td> <td>Used in conjunction with <var/cookie/>, <var/header/>, and <var/query-param/></td> <td></td></tr><tr><td><a href="#remote-addr">remote-addr</a></td> <td>Evaluates to true if the remote address of the client matches the specified ip address</td> <td></td></tr><tr><td><a href="#remote-user">remote-user</a></td> <td>Evaluates to true if the user is authenticated and has the specified name</td> <td></td></tr><tr><td><a href="#secure">secure</a></td> <td>Evaluates to true if the ssl status of the request is equal to the specified value of true or false</td> <td></td></tr><tr><td><a href="#server-name">server-name</a></td> <td>Evaluates to true if the server name used by the client matches the specified value</td> <td></td></tr><tr><td><a href="#server-port">server-port</a></td> <td>Evaluates to true if the port used by the client equals the specified value</td> <td></td></tr><tr><td><a href="#user-in-role">user-in-role</a></td> <td>Evaluates to true if the user is authenticated and in the specified role</td> <td></td></tr></deftable-childtags></defun><s1 title="Logging and Debugging"><p>Logging for the name <code>com.caucho.server.rewrite</code>at the "finer" level reveals successful matches. At the "finest" level bothsuccessful and unsuccessful matches are logged.</p><example title="Logging example"><logger name="com.caucho.server.rewrite" level="finest"/></example><results>[1998/05/08 02:51:31.000] forward ^/foo: '/baz/test.jsp' no match[1998/05/08 02:51:31.000] forward ^/bar: '/baz/test.jsp' no match[1998/05/08 02:51:31.000] forward ^/baz: '/baz/test.jsp' --> '/hogwarts/test.jsp'</results></s1><s1 title="Examples"><s2 title="Redirect http:// requests to https:// requests"> <p> The desired behaviour is to redirect plain connections to SSL connections. </p> <example title="Desired behaviour"> http://anything.com/anything.html redirect => https://anything.com/anything.html </example> <example title="Configuration"> <host ...> ... <rewrite-dispatch> <redirect regexp="^" target="https://${host.name}"> <when secure="false"/> </redirect> </rewrite-dispatch> ... </host> </example></s2><s2 title="Make an alias for a web-app"> <p> The desired behaviour is to make it so that a web-app will match more than one url pattern. For example, a web-app is deployed in <code>webapps/physics</code> and available at <code>http://hostname/physics/</code>, the desired behaviour is to allow a request to <code>http://hostname/classroom/physics</code> to end up at the <code>/physics</code> web-app. </p> <example title="Desired behaviour"> http://hostname/classroom/physics forward => http://hostname/physics http://hostname/classroom/physics/anything forward => http://hostname/physics/anything </example> <p> The rewrite-dispatch tag is used at the <host> level. If it was placed in a <web-app> then it would be too late to forward to a different web-app because Resin would have already resolved the web-app. </p> <example title="Configuration"> <host> <rewrite-dispatch> <forward regexp="^/classroom/physics" target="/physics"/> </rewrite-dispatch> ... </example></s2><s2 title="Forward based on host name"> <p> The desired behaviour is to internally forward requests based on the host name. </p> <example title="Desired behaviour"> http://gryffindor.hogwarts.com/anything.html forward => /gryffindor/* http://slytherin.hogwarts.com/anything.html forward => /slytherin/anything.html http://hogwarts.com/anything.html forward => /anything.html </example> <p> The rewrite-dispatch tag is used at the <cluster> level. If it was placed in the <host> or the <web-app> then it would be too late to forward to a different host because Resin would have already resolved the host. </p> <example title="Configuration"> <cluster> ... <rewrite-dispatch> <forward regexp="http://gryffindor\.[^/]+" target="/gryffindor/"/> <forward regexp="http://slytherin\.[^/]+" target="/slytherin/"/> </rewrite-dispatch> ... </cluster> </example></s2></s1></body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -