Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 647161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:41:32+00:00 2026-05-13T21:41:32+00:00

In answering another persons question here on SO, I discovered that there is a

  • 0

In answering another persons question here on SO, I discovered that there is a small “bug” in my global redirect code.

I have wired up a Global class to an HttpModule. It’s job is to detect “http:/www.” in the URL and redirect the user to the NON www. version

Protected Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    'Force Removal of WWW
    Dim application As HttpApplication = TryCast(sender, HttpApplication)
    Dim url As Uri = application.Context.Request.Url
    Dim hasWWW As Boolean = If(url.ToString.StartsWith("http://www."), True, False) 'UrlRegex.IsMatch(url.ToString())
    If hasWWW Then
        Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
        application.Context.Response.Redirect(newUrl, False)
        application.Context.Response.StatusCode = 301
        application.Context.Response.End()

    End If

End Sub

The problem I’m having is that when it redirect a page http://www.example.com/AboutUs, the goal is to have it go to http://example.com/AboutUs (the rewritten page) but instead it’s going to http://example.com/Default.aspx?Slug=AboutUs (the original page).

I tried doing a bit of a hack by changing

    Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
    application.Context.Response.Status = "301 Moved Permanently"
    application.Context.Response.AddHeader("Location", newUrl.Replace("Default.aspx", "")) 

to

    Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
    newUrl = newUrl.Replace("Default.aspx?Slug=", "")
    newUrl = newUrl.Replace("Default.aspx", "")
    application.Context.Response.Status = "301 Moved Permanently"
    application.Context.Response.AddHeader("Location", newUrl) 

not something I want to do anyways since it’s a hack, but it didn’t work anyways.

Any advice on this would be very much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:41:32+00:00Added an answer on May 13, 2026 at 9:41 pm

    Here’s the answer that works

        Protected Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
            'Force Removal of WWW
            Dim application As HttpApplication = TryCast(sender, HttpApplication)
            Dim url As Uri = application.Context.Request.Url
            Dim hasWWW As Boolean = If(url.ToString.StartsWith(String.Format("{0}://www.", url.Scheme)), True, False)
            Dim forceWWW As Boolean = Boolean.TryParse(ICMS.Site.Settings.GetSettingsValue("ForceWWW"), False)
            'UrlRegex.IsMatch(url.ToString())
            If hasWWW Then
                Dim newUrl As String = UrlRegex.Replace(url.ToString(), String.Format("{0}://", url.Scheme))
                application.Context.Response.Redirect(newUrl.Replace("Default.aspx?Slug=", String.Empty), False)
                application.Context.Response.StatusCode = 301
                application.Context.Response.End()
            End If
    
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When answering another question, I realized that the following program does not quite do
As part of answering another question, I came across a piece of code like
The question arose when answering to another SO question ( there ). When I
As part of answering another question, I wanted to show that the insane level
When answering another question, it occurred to me that I maybe optimize some of
As part of answering another question, I wrote the following code whose behaviour seems
I was answering another question on here where the user had a ListView with
I was answering another question about creating a binding in code-behind, and my original
In answering another question someone pointed out that in C# you can access a
Answering another question about how const string data was stored in an executable a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.