Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Performance and...Performance and...301301's without using Modules
Previous
 
Next
New Post
3/25/2010 7:08 AM
 

Is it possible to setup 301 redirects without using modules (such as iFinity's URL Master).  I'm trying to read the requested URL and if it matches certain parameters then redirect to the correct page.  I'm quite new to asp/vb code so this is confusing me a fair bit right now.  :(

I believe (high degree of faith given my limited experience) the code for redirection I have written is ok but it will not fire.  I have written it in the Global.asax.vb file.  I'd like to correctly 301 redirect Home.aspx, default.aspx to root ('/') as well as the old /tabid/xx/default.aspx pages to their new friendly URL varients.

Example Code:

            If Request.Url.LocalPath.ToLower.EndsWith("oldurl.aspx")  Then
                    Response.Status = "301 Moved Permanently"
                    Response.AddHeader ("Location", "http://www.example.com/newurl.aspx")
            End If

I know there are paid for modules to do this job but I'd rather avaoid paying any money out and just writting in some code to do this.  I have searched far and wide and have drawn a blank so far.

Any help is greatly appreciated!

 
New Post
3/25/2010 7:35 AM
 

Hi

I would suggest you check with your hosting company if they are using IIS Mod-Rewrite. If this is the case (for example Crystaltech) you can use .htaccess to do your 301 redirects the same way as you would do on linux.

 

 

 
New Post
3/25/2010 8:01 AM
 

Thanks Matt, I have asked but they won't install it :(  My background is in Apache/PHP so I really wanted ISAPI rewrite on there but they refused.  I guess I'm just baffled by asp/iis a bit (I really have to learn more about this).

I think I need to place the code somewhere that will always be fired on page request.  I read somewhere that it needed to go in Application BeginRequest but I can't even find that.  I tried the code in Global BeginRequest instead but it failed.

 
New Post
3/25/2010 9:06 AM
 

I'm now trying this code, but it also fails to do anything:

            Dim strRequestPath As String
            strRequestPath = Request.Url.AbsolutePath.ToLower()

            Select Case strRequestPath
                Case "/old.aspx"
                    Response.Status = "301  Moved Permanently"
                    Response.AddHeader("Location", "/new.aspx")
                Case "/old2.aspx"
                    Response.Status = "301  Moved Permanently"
                    Response.AddHeader("Location", "/new2.aspx")     
            End Select


Again, this is going in to the global.asax.vb file in the Global_BeginRequest sub.  Any ideas why this isn't working?  Is there anywhere else I should try using the code?

Thanks in advance :)

 
New Post
3/29/2010 8:24 AM
 

Fixed!  DNN 301 redirects without modules.  Insert the code below in to global.asax and replace the old path with the new in the case sections.  Add as many as you like.  Not elegant or even the right way but a working way none the less.

<script runat="server">

Sub Application_BeginRequest()

                Dim strRequestPath As String

                strRequestPath = Request.Url.AbsolutePath()

                Select Case strRequestPath

                     Case "/old.aspx"

                           Response.Status = "301  Moved Permanently"

                           Response.AddHeader("Location", "new.aspx")

                     Case "/old2.aspx"

                           Response.Status = "301  Moved Permanently"

                           Response.AddHeader("Location", "new2.aspx")

                End Select

End Sub             

</script>

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Performance and...Performance and...301301's without using Modules


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out