Forum Discussion
Append Forward Slash to base URL in browser - redirect using an irule
How could I set up a redirect as per https://webpage.com >> https://webpage.com/ For when a user does not put the forward slash in the browser .. and the server does not perform this function. I am across the fact the browser will / should always send a URI “/” even if not typed in .
Have tried the below does not work (e.g. with Mozilla) as browser is sending uri = “/”
when HTTP_REQUEST { if { [HTTP::uri] eq "" } { HTTP::respond 302 Location "; } }
Also the below will not work as it creates a redirect loop ..
elseif { [HTTP::uri] eq "/" } { HTTP::respond 302 Location “; }
Is this easily doable – acknowledging the fact this is / is likely to be cosmetic… subject to browser behaviour.
3 Replies
Hi Basil
The browser would always send an URI, no matter if you don't enter one or not. If you don't it will resort to "/".
The only way an empty uri would reach a server afaik is if somebody is manually compiling a request and sending it. And if it did, the web server would reply with a 400 Bad request.
Please check the example below:
echo -ne "GET HTTP/1.1\r\nHost:mywebsite.com\r\nUser-agent: Mozilla/5.0\r\n\r\n" | nc 172.30.175.33 5919 HTTP/1.1 400 Bad Request Content-Type: text/html; charset=us-ascii Server: Apache Date: Wed, 21 Dec 2016 05:12:39 GMT Connection: close Content-Length: 324 Bad Request Bad Request - Invalid URL HTTP Error 400. The request URL is invalid.
The reason this is creating a redirect loop:
if { [HTTP::uri] eq "/" } { HTTP::respond 302 Location “https://webpage.com/"; }
You're sending the user back to "/", which is set to send the user to "/"... and so forth. 🙂
Hope that answered your question?
/Patrik
Hi! I guess I should have been clearer in my answer too... 🙂
IF by slim chance some user would send a request with an empty URI your original rule would do it:
when HTTP_REQUEST { if { [HTTP::uri] eq "" } { HTTP::respond 302 Location "https://webpage.com/"; } }
As for the forcing the browser to show "/" when the user accesses your site, this is purely on the client side.
- Chrome does not show it
- Edge does not show it (does not even show the protocol)
- Internet explorer shows it
But in all cases, what's sent to the server is another thing. Chrome and Edge still sends "/", they just don't show it. To change this behavior I suppose the browser settings would be a good start. 🙂
/Patrik
- Stanislas_Piro2
Cumulonimbus
Hi Basil,
Can you post the request when requesting https://webpage.com?
the request must be:
GET / HTTP/1.1 Host: webpage.com User-agent: Mozilla/5.0 Connection: close
If the browser does not set the
, is there some string inserted between GET and HTTP?/
How the F5 HTTP profile parse the request? does it raise an error? does it parse HTTP/1.1 as the HTTP::uri?
Recent Discussions
Related Content
* 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