Forum Discussion
Steffen_Lenz_29
Nimbostratus
Aug 21, 2007Rewrite URL
hi,
i searched here in this forum a long time for a irule that satisfy my needs but i didn`t get this things started.
I want to rewrite (not redirect!) URIs as follows:
http://server1.company.de -> http://server10.company.de:port
http://server1.company.de/directory1 -> http://server11.company.de
http://server1.company.de/directory2 -> http://server12.company.de/directory
Is there anybody who can give me an example of a irule whch will rewrite this URIs?
Thanks!
Regards,
Steffen
19 Replies
- hoolio
Cirrostratus
Kirk added a very complete ProxyPass codeshare rule (Click here) which should allow you to do this.
Else, if that's more than what you're looking for, you could use 'HTTP::header replace Host newhost' to rewrite the Host header and HTTP::uri to set the URI before the request is sent to the pool. You may also need to rewrite response content (with a stream profile) and response headers (with HTTP::header replace) to make the change transparent to clients.
Take a look at the proxypass rule and the wiki pages for the various commands and reply with any questions.
Aaron - Steffen_Lenz_29
Nimbostratus
Posted By hoolio on 08/21/2007 3:21 AM
Else, if that's more than what you're looking for, you could use 'HTTP::header replace Host newhost' to rewrite the Host header and HTTP::uri to set the URI before the request is sent to the pool. You may also need to rewrite response content (with a stream profile) and response headers (with HTTP::header replace) to make the change transparent to clients.
Take a look at the proxypass rule and the wiki pages for the various commands and reply with any questions.
Aaron
Thanks. I`ve found Kirks solution before but i think its too complex. I`ve made the following irule but in my client`s browser i get an error:
""
Not Found
The requested URL /directory1 was not found on this server.
""
my irule:
""
when HTTP_REQUEST {
if { [HTTP::uri] contains "directory1"} {
HTTP::header replace Host server11
}
}
""
In addition how do i edit the response content?
Regards,
Steffen - Kirk_Bauer_1018
Altostratus
You can use a stream profile to modify the response content. Do consider using my ProxyPass iRule and saving yourself a lot of time -- that iRule has been thoroughly tested and you need not modify the rule itself, just create and manage a data group to go along with it. - Kirk_Bauer_1018
Altostratus
And the error you are getting is because you changed the host header but did not modify the request URI to remove the "directory1" portion. Also be aware that you have to reverse this whole process if the server sends redirects which are very common. For example, if you got the URI http://server1.company.de/directory2/ to successfully map to http://server12.company.de/directory/ try going to the same URI without the trailing slash. The server will send the browser a redirect to http://server12.company.de/directory/ which you then have to modify back to http://server1.company.de/directory2/ in the headers on the way back to the client. - Steffen_Lenz_29
Nimbostratus
hi kirk,
i`ve used your irule, but i got the following errors:
line 13: [wrong args] [virtual]
line 22: [wrong args] [virtual]
line 50: [wrong args] [virtual]
line 74: [wrong args] [virtual]
line 85: [wrong args] [virtual]
line 90: [wrong args] [virtual]
line 99: [wrong args] [virtual]
line 129: [wrong args] [virtual]
Do i have to replace "[virtual]" ?
Regards,
Steffen - hoolio
Cirrostratus
The [virtual] command is only valid in 9.4. You can replace all instances of [virtual] with [virtual name] for versions < 9.4. It's just info that's logged anyhow, but this will provide the same output.
Wiki page on [virtual]
Click here
Aaron - Steffen_Lenz_29
Nimbostratus
hi,
i`ve replaced [virtual] by [virtual name]. There is no more error.
Unfortunately i doesn`t get the target rewrited, the client`s browser get the content of the webserver which is defined in the Pool of the Virtual Server.
My Config:
Virtual Server: "testf5web-ssl"
Resource: iRule "Rewrite_Netmon"
iRule: "Rewrite_Netmon"
Data Group Type "String"
Data Group Name: "ProxyPasstestf5web-ssl"
Data Group Record: "testf5web.fiz-karlsruhe.de/netmon/ netmon.fiz-karlsruhe.de"
URL called: "testf5web.fiz-karlsruhe.de/netmon/"
What i`m doing wrong?
Regards,
Steffen - Kirk_Bauer_1018
Altostratus
You must at least have a "/" after the hostname in each item in each entry. So in your case the data group record would be:
testf5web.fiz-karlsruhe.de/netmon/ netmon.fiz-karlsruhe.de/
Here is a brief excerpt from the manual:
One thing that needs to be clarified is the usage of a trailing forward-slash in the examples above. Unless you really know what you are doing and are trying to do something unusual, simply follow these rules:
•For the left-hand-side entry only end the entry with a forward-slash if there is no other path. So “www.company.com/” and “/” are valid entries, but you would not want to end “www.company.com/path” or “/path” with a forward-slash.
•For the right-hand-side entry follow the same rule as the left-hand-side entry above except you should always end the right-hand-side entry in a forward-slash if the left-hand-side entry also ends in a forward-slash. - Kirk_Bauer_1018
Altostratus
I don't know why they couldn't have left [virtual name] as a valid command in 9.4.X. I will update the docs to mention this. - hoolio
Cirrostratus
Yep. [virtual name] in 9.4 could work as long as 'name' was a reserved word and wasn't used as the actual virtual server name...
Alternately, it would be helpful if you could get the BIG-IP version from an iRule command so you could programmatically change the commands used for version-specific scenarios.
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
