Welcome to WebmasterWorld Guest from 107.21.183.163

Forum Moderators: ocean10000

Message Too Old, No Replies

301 rewrite problems in global.asa

     

spiral

1:37 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



I've never done 301s in asp, always worked with .htaccess and things were good.

Currently need to redirect a whole site to the root of a new site (sitewide to root). I only have FTP access to the server. Site is old asp site using some sort of cms.

I tried the below code and got an error message:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
%>

This is my global.asa file:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

Can anyone please, please post the modified code for a 301? Also, I'm new to developing, and not sure about line breaks in all the asp code snippets I see online.

Ocean10000

1:51 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

spiral

2:09 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



Thanks for the code Ocean, but it's not working for me.

I pasted as above, only change was my real URL. It worked once, then stopped.

Ocean10000

6:02 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
'Destroys the Session. So that future calls will retrigger this code.
Session.Abandon
'Sends buffered output immediately.
Response.Flush
'Stops processing the .asp file and returns the current result.
Response.End
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

References
Response Object [msdn.microsoft.com]

Session Object [msdn.microsoft.com]