Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Per-page redirection in IIS7

  • 06-01-2013 12:42PM
    #1
    Registered Users, Registered Users 2 Posts: 6,681 ✭✭✭


    I am tweaking the FeetFirst.ie web site. I had to redirect 3 pages to 3 different internal urls e.g.
    http://www.feetfirst.ie/page.aspx?pageid=592 -> http://www.feetfirst.ie/page.aspx?subsectionid=634

    The hosting company's knowledge base says that ISAPI Rewrite 3 is installed which means that it uses .htaccess and that the rules are interchangeable with Apache's mod_rewrite.

    I tried the following but it did not work:
    RewriteEngine on
    
    Redirect 301 /page.aspx\?pageid=592 http://www.feetfirst.ie/page.aspx?subsectionid=634
    Redirect 301 /page.aspx\?pageid=593 http://www.feetfirst.ie/page.aspx?subsectionid=619
    Redirect 301 /page.aspx\?pageid=594 http://www.feetfirst.ie/page.aspx?subsectionid=62
    

    The hosting company would not help. They would only confirm that ISAPI Rewrite was enabled on the server.

    I ended up implementing it in the C# files but I am not happy with this solution (this was hacked into existing code in the page.aspx file):
    <script runat="server">
        int GetParameter(string Name)
        {
            try
            {
                return int.Parse(Request.Params.Get(Name));
            }
            catch
            {
                return 0;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int SectionID = GetParameter("SectionID");
                int SubSectionID = GetParameter("SubSectionID");
                int PageID = GetParameter("PageID");
    
                // Redirect some pages to others, based on code from: http://www.rapidtables.com/web/tools/redirect-generator.htm
                // Redirect Mizuno 5k Winter Series left menu page to section in black menu.
                if (PageID == 592) {
                  Response.Status = "301 Moved Permanently";
                  Response.AddHeader("Location","http://www.feetfirst.ie/page.aspx?subsectionid=634");
                  Response.End();
                }
                // Redirect Good Friday Run left menu page to section in black menu.
                if (PageID == 593) {
                  Response.Status = "301 Moved Permanently";
                  Response.AddHeader("Location","http://www.feetfirst.ie/page.aspx?subsectionid=619");
                  Response.End();
                }
                // Redirect Killarney Women's Mini Marathon left menu page to section in black menu.
                if (PageID == 594) {
                  Response.Status = "301 Moved Permanently";
                  Response.AddHeader("Location","http://www.feetfirst.ie/page.aspx?subsectionid=628");
                  Response.End();
                }
            }
        }
    </script>
    

    What am I doing wrong in .htaccess?
    Is there a super simple test that I can add to .htaccess to confirm that ISAPI Rewrite is enabled and working?


Advertisement