There are many ways to implement static html pages, but not everyone knows how to implement static pages. So now, the editor of Foxin will introduce to you how to implement static pages in Asp. Interested friends come and have a look.
1. Use isapi_rewrite to dynamically link and rewrite the html static URL. isapi_rewrite is a DLL component, and re_write is a module in iis. This filter implementation uses regular expressions to map dynamic web URLs to static URLs. For example, you can convert news.asp?id=95 into news/95.html through re_write. The mapping regular expression is set in the httpd.ini file.
To give a small example: to deal with data page turn, the writing method is:
more_<%=page%>_<%=type%>.html (Note: page is the number of pages turned, type is the data type) Expression form: more_1_95.html
If you turn to the next page, it is: more_2_95.html, and continue the loop of the next page, it is:
more_3_95.html, and so on.
However, you need to add the following code to the httpd.ini file:
rewriterulle /more_(d+)_(d+).html /jsp tutorial/more.asp?page=$1&type=$2 [n,i] string 9
If your dynamic program has multiple parameters to be passed, then add multiple (d+), as follows:
rewriterulle /more_(d+)_(d+)_(d+).html /asp/more.asp?page=$1&type=$2&type2=$3 [n,i]
Advantages: There is basically no need to make any changes in the program. Trouble: To achieve this, you need to control IIS, so when you rent someone else’s server, you need to contact the service provider first. (Of course this is for Asp, there is no need to do asp.net tutorial - you can directly put the DLL assembly into the bin in the program and then configure it appropriately)
2. iis's 404 error handling mechanism: By customizing errors, turn to the processing page we prepared. However, this scalability needs to be studied, and the overall requirements for program processing are also high, and it is not very suitable for practical applications.
First, set site properties - custom errors
Find http error 404, and then edit the properties -> Message type and select url->url to fill in "/index.asp", or your error handling page.
In this way, for example, when a user or a spider visits http://cn/12345.html (12345 is the id of the article in the database tutorial). Since some pages do not exist, a 404 error was triggered. Turning to index.asp
Add in index.asp
The code copy is as follows:currdomain=request.servervariables("http_host") 'Current access domain name
currurl=replace(request.servervariables("query_string"),"404;http://"&currdomain&":80","") 'Currurl accessed
The currurl at this time should be: 12345.html.
3.
1. Create a new folder info (because the page URL of the final access information is http://localhost/info/?1.html)
2. Create a new default.asp file in the info folder (that is the page of the default homepage)
The contents of the default.asp file are as follows
The code copy is as follows:<%
currdomain=request.servervariables("http_host") 'Current access domain name
currurl=replace(request.servervariables("query_string"),"404;http://"&currdomain&"/info/?","") 'Curror accessed url
id=replace(currurl,".html","")
%>
where id is the passed parameter
If there are multiple parameters, you can pseudo-statically turn the url into info/?1-2-3.html
Among them, 1, 2, and 3 each represent the values of three parameters, and the separated strings can be proposed separately.
Real html static page
Write html code into a file and generate a file in .html format
The code copy is as follows:<%
filename="test.htm"
if request("body")<>"" then
set fso = server.createobject("scripting.filesystemobject")
set htmlwrite = fso.createtextfile(server.mappath(""filename""))
htmlwrite.write "<html><head><title>" request.form("title") "</title></head>"
htmlwrite.write "<body>Output title content: " request.form("title") "<br />Output body content:" request.form("body") "</body></html>"
htmlwrite.close
set fout=nothing
set fso=nothing
end if
%>
<form name="form" method="post" action="">
<input name="title" value="title" size=26>
<br>
<textarea name="body">body</textarea>
<br>
<br>
<input type="submit" name="submit" value="generate html">
</form>
2. However, it is very inconvenient to generate html files according to the above method. The second method is to use template technology to replace the value of the special code in the template with the value accepted from the form or database field to complete the template function; to generate html files from all the template codes that were finally replaced. This technology is used more, and most cms use this method.
template.htm ' //Template file
The code copy is as follows:<html>
<head>
<title>$title$ by aspid.cn</title>
</head>
<body>
$body$
</body>
</html>testtemplate.asp '// Generate html
<%
dim fso,htmlwrite
dim strtitle, strcontent, strout
'// Create a file system object
set fso=server.createobject("scripting.filesystemobject")
'// Open the web template file and read the template content
set htmlwrite=fso.opentextfile(server.mappath("template.htm"))
strout=f.readall
htmlwrite.close
strtextle="generated webpage title"
strcontent="generated web page content"
'// Replace the tags in the template with real content
strout=replace(strout,"$title$",strtitle)
strout=replace(strout,"$body$",strcontent)
'// Create the static page to be generated
set htmlwrite=fso.createtextfile(server.mappath("test.htm"),true)
'// Write content to the web page
htmlwrite.writeline strout
htmlwrite.close
response.write "The static page was generated successfully!"
'// Release the file system object
set htmlwrite=nothing
set fso=nothing
%>
This article introduces how to implement static pages in Asp. Friends who need it can refer to it.