Forum Moderators: open
`<--- %@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " http://www.example.com"
>`
This is fine, I guess, but I am confused as to how I change the redirect URL on each page.
For example:
www.example/viewitem.asp?=a12349 www.example/viewitem.asp?=a12350
www.example/mainpage.asp www.example.com/viewcategor.asp?=cat17
The variations go on and on 100,000 times with new pages added daily.
If I use the ASP redirect code, do I need to alter each piece of code to reflect the exact page to redirect to? (100,000 times and on the fly) For example, below:
********************************************
`<--- %@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " www.example/viewitem.asp?=a12349"
>`
*********************************************
`<--- %@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " www.example/viewitem.asp?=a12350"
>`
*********************************************
`<--- %@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " www.example/mainpage.asp"
>`
********************************************
`<--- %@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " www.example.com/viewcategor.asp?=cat17"
>`
********************************************
Or is there a ‘catch all’ that will just direct browsers and spiders to the www version of each page?
As for my HTML pages I am apparently out of luck. However, I could solve half the problem if I could figure out an easy way to implement the ASP redirect on a dynamic, database driven ASP site.
[edited by: Xoc at 1:44 am (utc) on April 26, 2006]
[edit reason] examplified urls [/edit]
Now check the Domain_Name to see if it is the www version, if not, then 301 redirect to the properly constructed URL using the "http://www.example.com", PATH_INFO and QUERY_STRING serverVariables.
[edited by: Xoc at 1:44 am (utc) on April 26, 2006]
[edit reason] examplified urls [/edit]
Say I wanted to redirect on the fly using your method, anyone or any spider coming to:
http://example.com/items/stock.php?=17354
to
http://www.example./items/stock.php?=17354
What ASP snippet(s) would I put on the top of all my asp pages?
[edited by: Xoc at 1:45 am (utc) on April 26, 2006]
[edit reason] examplified urls [/edit]
<%
If Request.ServerVariables("SERVER_NAME")="example.com" then
strRedirectURL = "www.example.com" & Request.ServerVariables("URL")
if Request.QueryString <> "" then strRedirectURL = strRedirectURL & "?" & Request.QueryString
Response.Status="301 Moved Permanently" Response.AddHeader "Location", strRedirectURL
end if
%>
I get the following error when trying to view any page I put this on:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/index.asp, line 18
Response.Status="301 Moved Permanently" Response.AddHeader "Location", strRedirectURL
----------------------------------------^
[edited by: Xoc at 1:46 am (utc) on April 26, 2006]
<%
If Request.ServerVariables("SERVER_NAME")="mydomain.com" then
strRedirectURL = "www.example.com" & Request.ServerVariables("URL")
if Request.QueryString <> "" then strRedirectURL = strRedirectURL & "?" & Request.QueryString
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", strRedirectURL
end if
%>
When http://example.com/ is entered it returns:
http://example.com/www.example.com/index.asp
[edited by: Xoc at 1:47 am (utc) on April 26, 2006]
<%
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.mydomainname.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://" & domain_name & "/" & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
response.Write theURL
end if
%>
You can change the:
response.write theURL
to:
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
I tried your code and with http://example.com and I get the following redirect error.
******************************
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
******************************
Here is the code snip I used:
<%
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.example.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://" & domain_name & "/" & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
end if
%>
Also, the URL that is in the address bar is:http://example.com//index.asp
Boy do I wish I went with PHP/Apache way back when so I could just enter a couple lines of code to my .htaccess file and the 301 redirect would be done.
[edited by: Xoc at 1:47 am (utc) on April 26, 2006]
I do not know anything about the structure and use of .NET or .asp pages.
I handle marketing for a site and the webmaster constructed the site in .asp.
From the information I have gathered so far, due to the Big Daddy update, we have been trying to determine what shot our 3000+ page site into supplementals.
One: We have duplicate Titles generated on each e-commerce page. If page titles are changed to be very specific for each product on each page, does each page have to be hand-altered? Or is there a way to assign Titles that are not duplicate at all?
Two: The webmaster could care less about SEO. I have to try to figure that out and tell him. I asked him how the multiple domains owned by the company were handled to redirect to the main www.example.com web site files. His reply was - "Server-side ASP. If the URL is not www.example.com, we redirect to www.example.com. This will still produce an HTTP GET status code of 200..."
Elsewhere on webmasterworld, I read the following:
"If you have your www and non-www pages both accessible on your site (with 200 status) then you have "duplicate content". In this case you must use the 301 redirect. It will get the whole site properly listed and fully indexed as ONE version.
If you do not use the redirect you will end up with split PR and many pages that show as URL-only, and many pages that show as supplemental for both the www and the non-www version, and maybe quite a few pages that fail to get indexed at all under either version."
If the statement directly above is the case, what specifically should I tell the webmaster to do? How should multiple domains be structured to 301 to the main web site that is proper on an asp site?
We do run our own server, so server-side includes and any type of server-side techniques could be implemented.
[edited by: Xoc at 1:48 am (utc) on April 26, 2006]
try changing this line:theURL = "http://" & domain_name & "/" & HTTP_PATH
to
theURL = "http://" & domain_name & HTTP_PATH
see if that works
I changed to:
<%
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.example.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://" & domain_name & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
end if
%>
Now the domain that appears in the address bar is correct but I am still getting the error: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
Surely there must be someone doing an ASP redirect on a dynamic website that can flip me the snippet of ASP code they are using to do a page based 301 redirect.
[edited by: Xoc at 1:49 am (utc) on April 26, 2006]
Thanks for your persistence. However, I made the changes and I am still getting the same error when typing in example.com: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
My snippet is now:
<%
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.EXAMPLE.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://" & domain_name & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Clear
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
Response.Flush
Response.End
end if
%>
[edited by: Xoc at 1:49 am (utc) on April 26, 2006]
I am still on the hunt for an ASP 301 redirect snippet that works for a large dynamic website. I can find, snippets to redirect a single page, but I have 100,000s of pages with different URLs so I need something that will work site wide. Someone out there must have a proven snippet of 301 ASP code on their windows hosted dynamic site that they use?
I am on a shared windows box so my only hope to do a 301 redirect is via code on every page on my site. An IIS level solution is not allowed.
Any ideas, anyone?
An IIS level solution is not allowed.
Move to a host that has ISAPI Rewrite installed and offers support for implementation. The only way to effectively manage what you have going on is through an ISAPI filter. A few lines in your httpd.ini file and you're ready to go.
I believe there are some built in facilities for basic rewriting in ASP.NET. But, my understanding is that ISAPI Rewrite takes it way beyond the basics.
The place I use is quick with support (I guess it doesn't take long to say no) but they don't let their shared clients do anything outside the box.
I'd try to sell your host on the fact that having ISAPI Rewrite installed and available for clients would put them a step or two above their competition. At $69.00 for a single server license (unlimited domains), it is the only solution available for Windows that is comparable to the Apache Mod_Rewrite.
You are going to find it very difficult to find any public hosting companies that offer the ISAPI filters. Why? Because most, if not all, are afraid of installing something they are not familiar with.
Hey, all you Windows hosting companies! Get your act together and start offering rewrite capabilities for your clients. If you don't, we're going to lose more market share to the UNIX side. What the heck is the holdup? The installation of ISAPI Rewrite takes about 15 minutes. After that, you drop an .ini file in the root of each web and let the client configure from there. What I recommend is that you have a default .ini and provide commented examples that they can use for simple redirect routines that they'll need on a regular basis.
One: We have duplicate Titles generated on each e-commerce page. If page titles are changed to be very specific for each product on each page, does each page have to be hand-altered?
I sure hope not. Are you generating static html pages from your database? Or, are you generating pages on the fly based on the request?
Or is there a way to assign Titles that are not duplicate at all?
Absolutely. Use a variable from the database. I'll assume you have titles for each product?
<title>Insert Variable Here</title>
Two: The webmaster could care less about SEO. I have to try to figure that out and tell him. I asked him how the multiple domains owned by the company were handled to redirect to the main www.company.com web site files. His reply was - "Server-side ASP. If the URL is not www.company.com, we redirect to www.company.com. This will still produce an HTTP GET status code of 200..."
Ummm, you may want to seek some technical help if you have your own servers.
Elsewhere on webmasterworld, I read the following: "If you have your www and non-www pages both accessible on your site (with 200 status) then you have "duplicate content". In this case you must use the 301 redirect. It will get the whole site properly listed and fully indexed as ONE version.If you do not use the redirect you will end up with split PR and many pages that show as URL-only, and many pages that show as supplemental for both the www and the non-www version, and maybe quite a few pages that fail to get indexed at all under either version."
If the statement directly above is the case, what specifically should I tell the webmaster to do? How should multiple domains be structured to 301 to the main web site that is proper on an asp site?
Multiple domains? 301 to main website? How many domains are there?
About the multiple-domains: We had one main site. The site owner bought 7 other domains that covered category types consistent with the product line.
I found some information out on the net how to handle these as well. This is "supposedly" the correct way to handle multiple domains.
We set up an account on another server away from our main site/server.
One secondary domain (from the multiple group) was chosen as the Main Secondary domain.
We 301'd the remaining 6 domains (all have their own basic account) to the Main Secondary Domain. We then 301'd the Main Secondary Domain to the Primary Domain Web Site.
Now - supposedly, that is the proper way to handle the multiple - domain issue. I'd like to hear if I've been misinformed ;-)
Thanks!
You are going to find it very difficult to find any public hosting companies that offer the ISAPI filters. Why? Because most, if not all, are afraid of installing something they are not familiar with.
It took one call to the Windows hosting service I was going to go with 3 years ago instead of the one I currently use. But they do offer ISAPI Rewrite on their shared plans. Too bad I wanted to save that $15 a month way back then...
Now I need to get my nerve up to move my site, SQL and all.
So if you have a dynamic ASP site and your Windows IIS host won't allow you to do the server-side IIS tweak, here is the code you can add to all the ASP pages on your website:
<%
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.example.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://www.example.com" & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Clear
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
Response.Flush
Response.End
end if
%>
Of course, be sure to replace domain.com with your own domain name and in lower case only.
I tested this code on my site and it works great.
If you use this code, I suggest you save it in a file named redirect.asp and then add to the top of each file on your site the following snippet:
<!-- #Include file="redirect.asp" -->
If you have files in sub-directories add the appropriate path info or use a fully qualified path.
Enjoy!
[edited by: Xoc at 1:51 am (utc) on April 26, 2006]
So if you have a dynamic ASP site and your Windows IIS host won't allow you to do the server-side IIS tweak, here is the code you can add to all the ASP pages on your website:
Wouldn't this short block of code suffice?
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.example.com/new-page.asp"
%> Or, am I missing something? :(
And this short block of code for ASP.NET...
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.example.com/new-page.asp");
}
</script>
Dim Domain_Name, theURL, QUERY_STRING, HTTP_PATH
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "www.example.com" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
If Left(HTTP_PATH, 8) = "/default" Then
HTTP_PATH = ""
End If
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://www.example.com" & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Clear
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
Response.Flush
Response.End
end if
I added in..
If Left(HTTP_PATH, 8) = "/default" Then
HTTP_PATH = ""
End If
So the URL that it is sent to does not have the /default.asp on the end of it.
If anybody can see anything wrong with this script. I would love to here.
I have also changed my internal back links to <a href=”/”> as apposed to to <a href=”default.asp/”> .I notice that Google uses this technique for its home logo link.
[edited by: tedster at 4:47 pm (utc) on Mar. 26, 2006]
[edit reason] use example.com in code [/edit]
Wouldn't this short block of code suffice?<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.example.com/new-page.asp"
%>
Yes your code would work for one page, but I was looking for a one size fits all snippet of code that would redirect to the proper URL on the fly for each page on a large dynamic website.
Ipjunkie,
I added your tweak for the default.asp or in my case the index.asp at the end of it and fixes the one problem I had with the code on my home page. As far as I can tell, your snippet works great.