Forum Discussion

Jim_Jack_103645's avatar
Jim_Jack_103645
Icon for Nimbostratus rankNimbostratus
Feb 19, 2007

remove trailing periods

We are receiving a number of users trying to access our webpages but they put a trailing period in the URL e.g.:

 

'http://www.thesite.com./Default.aspx'

 

Note the '.com.'

 

How can I remove the trailing period so that the headers match?

 

i.e. URL should be:

 

'http://www.thesite.com/Default.aspx'

2 Replies

  • It seems a bit strange that users would add a trailing period, but...

    To remove a trailing period if there is one, you can use 'string trimright', like this:

    
    when HTTP_REQUEST {
       if { [HTTP_HOST ends_with "." }{
          HTTP::host [string trimright [HTTP::host] "."]
       }
    }

    To test this with logging, you can use this:

    
    when HTTP_REQUEST {
       if { [HTTP_HOST ends_with "." }{
          set host_original [HTTP::host]
          set host_trimmed [string trimright [HTTP::host] "."]
          log local0. "\$host_original: $host_original"
          log local0. "\$host_trimmed: $host_trimmed"
          HTTP::host [string trimright $host_original "."]
       }
    }

    For details on the string command, you can check the TCL man page for string (Click here).

    Aaron
  • Many thanks.

     

    As usual, the guy who got the training has moved on and I have inherited the work :-)

     

    I really appreciate the response