Forum Moderators: open
Create search engine friendly static pages from a dynamic page in ASP
Let's say you've got a page called
product.asp which receives a querystring product_id, as in /products/product.asp?product_id=351 In your dynamic page, you display the product based on the
product_id you receive. Change the
product.asp page so the entire contents fall within a function called show_product(product_id), as in
<%function show_product(product_id)
'old product.asp page including any html etc.
end function%>
product_id 351:
<!-- #include file="product.asp"-->
<%call show_article(351)%>
Here's how to generate a file like that for every product_id in the database. Don't forget to use your own dsn, and to ensure you have write permission on the directory (here the directory is called products)
<%
set objconn=server.createobject("adodb.connection")
set objrs=server.createobject("adodb.recordset")
objconn.open("your_dsn")
set fso=server.CreateObject("Scripting.FileSystemObject")
const fc_path="products\"
const fc_OverWrite=truesql="select product_id from products"
set objrs=objconn.execute(sql)
if not objrs.eof then
while not objrs.EOF
sf_name=objrs("product_id")&".asp"
fc_hostpath=Request.ServerVariables("Appl_Physical_path")
set sf_stream=fso.createtextfile(fc_hostpath & fc_path & sf_name,fc_overwrite)
sf_stream.writeline "<" & "!-- #include file=" & chr(34) & "product.asp" & chr(34) & "-->"
sf_stream.writeline "<" & "%call show_product(" & objrs("product_id") &")%" & ">"
sf_stream.close
set sf_stream=nothing
objrs.Movenext
wend
end if
%>
So now, instead of calling /products/product.asp?product_id=351 you simple call /products/351.asp
but best of all, you still have all your code in one page (product.asp) so any global changes are still just as easy to make.