Forum Discussion
Nlepore_67643
Nimbostratus
Jan 25, 2013Having issues with redirect
I'm trying to redirect certin pages to https, based on URI in a class.
Looks to be working for the default.aspx page, but not the others.
when HTTP_REQUEST {
if {[HTTP::path] equals "/"}{
HTTP::redirect /default.aspx
} elseif {[class match [string tolower [HTTP::uri]] contains secured_uris]}{
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
The class includes;
/default.aspx
/contact_us.aspx
is it because I'm doing the redirect first?
8 Replies
- Arie
Altostratus
- Any errors in the log?
- Redirecting based on a URI that contains /default.aspx is risky, is it is quite conceivable that you'll have a path like /products/default.aspx sooner or later.
I'd recommend using "starts_with".
In addition, I'd use HTTP::path instead of HTTP::uri to check the request, as there's always a risk that a developer (or .NET) includes a path in a query string. - Is it really necessary to redirect from "/" to "/default.aspx"? From a web hosting perspective you'll want to avoid people visiting the default page of a folder by name.
- If you're redirecting the home page to HTTPS it would make sense to do that right away, rather than redirecting to /default.aspx on port 80 first and then to port 443.
- Instead of using HTTP::redirect you may want to consider using HTTP::respond with response code 301, since those are cached by clients and 302s are not. (Be sure to disable your own browser cache during development and troubleshooting, though!)
- What happens if you go directly to /default.aspx? Do you get redirected?
- What does Fiddler show?
- What_Lies_Bene1
Cirrostratus
Try this;when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "http://[HTTP::host]/default.aspx" } elseif { [class match [string tolower [HTTP::uri]] starts_with secured_uris] } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } - Nlepore_67643
Nimbostratus
If that isn't the best way to write this, what is?
when HTTP_REQUEST {
if {[HTTP::path] equals "/"}{
HTTP::respond 301 location https://[HTTP::path]
} elseif {[class match [string tolower [HTTP::uri]] starts_with secured_uris]}{
HTTP::respond 301 location https://[HTTP::host][HTTP::uri]
}
} - What_Lies_Bene1
Cirrostratus
Looks good but I would add some white space around the brackets, enclose the redirect strings in quotes and use an uppercase L with Location, like so;when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::respond 301 Location "https://[HTTP::path]" } elseif { [class match [string tolower [HTTP::uri]] starts_with secured_uris] } { HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]" } } - Nlepore_67643
Nimbostratus
Seems to be still only securing the one page. Another in the "secured_uris" datagroup doesn't get redirected. - Nlepore_67643
Nimbostratus
I got it figured out, thanks for you help. - What_Lies_Bene1
Cirrostratus
Great. You're welcome. - Arie
Altostratus
Posted By Nlepore on 01/28/2013 09:09 AM
I got it figured out, thanks for you help.
What was it?
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