Forum Discussion
alinayesina_102
Nimbostratus
Mar 13, 2009Responce URI Masking/Hiding
We would like to consult on the possibility of performing a URL rewrite with the use of an iRule for domain.com. it’s not a good practice for our homepage to show as http://www.domain.com/home/default.htm, the ideal way is to only show www.domain.com which is good for search engine crawlers and improves our search rankings.
Would something like this work?
when HTTP_RESPONSE {
if { [HTTP::status] starts_with "3" } {
set origRedir [HTTP::header Location]
set newRedir [string map {"/home/default.htm" "" } [HTTP::header Location]]
HTTP::header replace Location $newRedir
log local0. "Original redirect: $origRedir."
log local0. "Rewritten redirect $newRedir"
}
}
14 Replies
- The_Bhattman
Nimbostratus
You could do something like the following:when HTTP_REQUEST { if { [HTTP::host] eq "www.domain.com" } { HTTP::uri /home/default.htm } }
This is a very simple example of how to take an ordinary request of http://www.domain.com/ and pass it to the web server with the full uri but still hid it from the client's URL Locator. That is of course the if there is something on the domain that redirects it back to using the full URI.
Hope this helps
CB
this would take the request www.domain.com - hoolio
Cirrostratus
You'd probably want to add a check so that you only rewrite requests to a URI of / to /home/default.htm:when HTTP_REQUEST { Check if requested URI is / and requested host is www.example.com if {[HTTP::uri] eq "/" and [string tolower [HTTP::host]] eq "www.example.com" Rewrite URI to /home/default.htm HTTP::uri "/home/default.htm" } }
Aaron - alinayesina_102
Nimbostratus
Thank You for taking time to respond! I'm actually attempting to do just the opposite. (Sorry, I must have made this confusing). When server response to the client with URI "/home/default.htm" I want to make it look for the client like it come from "/". So that client never know what is the default URI for the site is. - hoolio
Cirrostratus
First, I think the rule will accomplish that. I assume that currently, the client makes a request to www.example.com/, the server redirects them to http://www.example.com/home/default.htm, the browser follows the redirect updating the address bar to http://www.example.com/home/default.htm and displays the default.htm content. So this iRule prevents the server from having to redirect the client from / to /home/default.htm by rewriting the URI before the request is sent to the server.
If you use your original approach to rewrite the application's redirect from http://www.example.com/home/default.htm to http://www.example.com/, the client will probably get redirected in a loop from http://www.example.com/home/ to http://www.example.com/home/default.htm and back.
Out of curiosity, why are you trying to do this? Is it for ease of use or based on some security concern?
Aaron - alinayesina_102
Nimbostratus
Application team asked us to do this because getting www.site.com instead of full URI is good for search engine crawlers and improves site search rankings. True or not we got a request and now need to implement it.
I see what you are saying about the redirect happening in the loop. That making it an interesting problem.
Clint requests www.site.com
Server response with www.site.com/home/default.htm
Client then requests www.site.com/home/default.htm
I need LTM to intercept www.site.com and send it to /home/default.htm on the background, but how do I prevent client from seeing /home/default.htm when server response back with the page? - hoolio
Cirrostratus
The above iRule does just that. There is nothing in the response from the server that tells the client that the request was rewritten from / to /home/default.htm. The only way the client would see the change is if you redirected them from / to /home/default.htm.
If you're able to test the iRule, I think you'll see that it does what you're looking for.
Aaron - alinayesina_102
Nimbostratus
I just tested it! It did exactly what you said and more ... The test page that had a test image in it got a broken link in its place. The image URI is Http://www.example.com/apache_pb.gif. It also very possible that this will not happen on the production site since the production application is actually hosted on IIS. - hoolio
Cirrostratus
If you use this version it will only rewrite the requested URI if the URI is / and the host is www.example.com. It should not have any effect on images or any other non-/ request.when HTTP_REQUEST { Check if requested URI is / and requested host is www.example.com if {[HTTP::uri] eq "/" and [string tolower [HTTP::host]] eq "www.example.com" Rewrite URI to /home/default.htm HTTP::uri "/home/default.htm" } }
Aaron - alinayesina_102
Nimbostratus
I just wanted to thank you for your help! Application team tested and they are happy so far with the result. You are magician! (spooky avatar though) :D - gGnome_32510
Nimbostratus
My apologies for hijacking this thread, but I would greatly appreciate some help refining the iRule above:when HTTP_REQUEST { Check if requested URI is / and requested host is www.example.com if {[HTTP::uri] eq "/" and [string tolower [HTTP::host]] eq "www.example.com" Rewrite URI to /home/default.htm HTTP::uri "/home/default.htm" } }
I have implemented this and while it works ok, I would like to ammend it so that:
1) a visitor can receive any content under /home (ie /home/anydir and /home/anyotherdir/anysubdir) without the path becoming visible in the browser, and
2)further that the visitor not be allowed to reach www.example.com/anywhere_other_than_/home.
It seems like it should be easy enough to do, but nothing I have tried so far has worked.
Thanks much,
Gregg
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