Link to home
Create AccountLog in
Avatar of Bill Henderson
Bill HendersonFlag for United States of America

asked on

PHP to ASP translation

Hi,

I have a redirect script that I need to insert on certain site pages. I've done this with PHP, but I'm not sure what the equivalent code would be for ASP. The gist is to sense if www. is missing from the URL and insert it with a new header. Here is the PHP:


if(strstr($_SERVER['HTTP_HOST'],'www.')==false) header("LOCATION:https://www.website.com");

Can anyone tell me what would be the equivalent ASP line of code to accomplish this?

(Yes I know URL rewrite is a better option - in this case, however, I need to accomplish this only when the one particular ASP file loads.

Any suggestions?

Thank you

Bill
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Your choices are a 301
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>

or a simple
response.redirect("mypage.asp") or response.redirect("http://somesite.com/mypage.asp")
Avatar of Bill Henderson

ASKER

I think I should have mentioned - I want them to be redirected to the same page. In other words - I'm just trying to insert www. and take them right back to this page. Won't it go into some kind of loop?

We want to redirect ONLY if they don't have www. in the URL to www. of the same asp file.

Does this make sense?

Bill
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks for the help!