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 } }
- 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" } }
- 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. - 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. - 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. - 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" } }
- 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" } }
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