Important alert: (current site time 7/15/2013 10:31:16 PM EDT)
 

article

Extended Urls / Fake Urls

Email
Submitted on: 7/30/2004 11:27:35 PM
By: Mr.Miagi  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 9008
(About the author)
 
     :How to extend your urls dynamically using a Mysql Database without having file structures for every directory in your Url's, this code will improve search engine status of your website and much more.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

404.asp

this page should be put as your custom error page for 404 http errors.

<%option explicit%>

<%

dim refer, indexc, strpage,strpagename, dbcon, connection, sql, dbrs, realpage

refer=Request.ServerVariables("QUERY_STRING")

indexc=instrrev(refer,"/")

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ getting the number of "/" in refer

'+ and stripping them off

'+ then removing the .htm or .html from them

'++++++++++++++++++++++++++++++++++++++++++++++++++

if (indexc>0) then

strpage = Right(refer,Len(refer)-indexc)

refer = Left(refer,indexc-1)

end if

strpage=replace(strpage,".html","")

strpage=replace(strpage,".htm","")

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ connection strings...

'+ sql= all fields where the page name is the requested url

'+ that we stripped above

'++++++++++++++++++++++++++++++++++++++++++++++++++

set dbcon = server.createobject("adodb.connection")

connection = "Driver={Mysql}; Server=69.56.199.234; Database=; UID=; PWD=;"

SQL = "SELECT * FROM `pages` WHERE PageName='"&strpage&"'"

dbcon.open(connection)

set dbrs = server.CreateObject("adodb.recordset")

dbrs.open sql, dbcon

if not dbrs.eof then

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ setting our variables

'+ setting the session of the pageID since we cannot

'+ transfer regular variables in server.transfer

'++++++++++++++++++++++++++++++++++++++++++++++++++

set realpage=dbrs.fields("realpage")

session("PageID")=dbrs.fields("PageID")

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ Sending the user a page, but not redirecting them

'+ (realpage) should be a field in our database with the page name. EX. "News"

'+ then we redirect them to our main page if it is a REAL 404 error

'++++++++++++++++++++++++++++++++++++++++++++++++++

server.transfer("/asp/"&realpage&".asp")

else

response.redirect("index.html")

dbrs.close

dbcon.close

end if

%>

 

Wwwroot/asp/urlgen.asp

this page contains the script which generates the fake urls

<%

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ this page writes our very false urls and puts

'+ them into links

'++++++++++++++++++++++++++++++++++++++++++++++++++

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ this is our domain, change it to your domain

'+ domain format must include http://'YOUR DOMAIN'/

'++++++++++++++++++++++++++++++++++++++++++++++++++

const url="http://halonation.com/"

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ our function for creating urls

'+ writes a link with the db urls, page directories

'+ and pagename+ a .htm

'++++++++++++++++++++++++++++++++++++++++++++++++++

Function CreateUrl(ID)

set dbcon = server.createobject("adodb.connection")

connection = "Driver={Mysql}; Server=69.56.199.234; Database=; UID=; PWD=;"

SQL = "SELECT * FROM `pages` WHERE PageID='"&ID&"'"

dbcon.open(connection)

set dbrs = server.CreateObject("adodb.recordset")

dbrs.open sql, dbcon

if not dbrs.eof then

pagename=dbrs.fields("pagename")

pagedir=dbrs.fields("pagedir")

CreateUrl=url&pagedir&pagename&".htm"

end if

dbrs.close

dbcon.close

End Function

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ our function for making the link name

'+ connects, gets linkname from the DB, and returns it

'++++++++++++++++++++++++++++++++++++++++++++++++++

Function CreateName(ID)

set dbcon = server.createobject("adodb.connection")

connection = "Driver={Mysql}; Server=69.56.199.234; Database=; UID=; PWD=;"

SQL = "SELECT `linktext` FROM `pages` WHERE PageID='"&ID&"'"

dbcon.open(connection)

set dbrs = server.CreateObject("adodb.recordset")

dbrs.open sql, dbcon

if not dbrs.eof then

CreateName=dbrs.fields("linktext")

end if

dbrs.close

dbcon.close

End Function

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ connection strings

'+ rowcount gets the number of rows total, for our Loop

'++++++++++++++++++++++++++++++++++++++++++++++++++

set dbcon = server.createobject("adodb.connection")

connection = "Driver={Mysql}; Server=69.56.199.234; Database=; UID=; PWD=;"

SQL = "SELECT COUNT(*) as Count FROM `pages`"

dbcon.open(connection)

set dbrs = server.CreateObject("adodb.recordset")

dbrs.open sql, dbcon

RowCount=dbrs("Count")

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ we loop Loopvar1 to Rowcount to write every link

'+ inside the DB, you might want to change this

'+ depending on which page it is displayed on.,

'+ just remove rowcount=dbrs("count") and replace with

'+ RowCount='YOUR COUNT

'++++++++++++++++++++++++++++++++++++++++++++++++++

for LoopVar1=0 to RowCount%>

<a href=<%=CreateUrl(LoopVar1)%>><%=CreateName(LoopVar1)%></a>

<br>

<%next

'++++++++++++++++++++++++++++++++++++++++++++++++++

'+ disposing of garbage..

'+

'++++++++++++++++++++++++++++++++++++++++++++++++++

set dbrs=nothing

set dbcon=nothing%>

 

 

 

Use This SQL To create your table correctly.

CREATE TABLE `pages` (

`PageID` tinyint(4) NOT NULL auto_increment,

`PageName` tinytext,

`PageDir` text,

`RealPage` tinytext,

`LinkText` tinytext,

PRIMARY KEY (`PageID`)

) TYPE=MyISAM;

 

To Conclude, write a <!--#include virtual=”./asp/urlgen.asp”--> in the body of your content page inside root/asp/ where you want your links generated. And always- CUSTOMIZE

Summary:
Extended Urls help with marketing, page rank on search engines, and much more. Without having to really make all the directories physically. I have a running example of this code at www.halonation.com/asp/news.asp, or any url you can think of that isn’t on my web server- J
On A side note, if anyone finds out a way to include char(63), &#63;, or ? into the server.transfer without getting a server.mappath error, please tell me, because that is one of the things that would make this script Very Good.

 

This Code has been provided free grant of use non-commercially

Copywrite synapse design 2003-2004


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/31/2004 5:37:22 AMSimon Nielsen

Hi, being an ASP novice, can you please make an access db version. The script seems to be very useful.
(If this comment was disrespectful, please report it.)

 
8/1/2004 3:35:11 AMMr.Miagi

I spose i could, its very easy tho, if i am right, my sql and everything should be compatible with access(which allows asp more functionality), so pretty much just change the driver info and connection string stuff to Microsoft Jet and it should work-but come on peeps, if you feel the same as simon does, vote :) lol my first entry-sorta-
(If this comment was disrespectful, please report it.)

 
8/16/2004 6:19:35 AM

This is neat, would like to see Access version as I am new to ASP.
(If this comment was disrespectful, please report it.)

 
1/17/2005 4:55:49 PMxearosphere

If you are interested in this, i am building a full website out of this script (i am mr. miagi), and its turning out really well, with full capabilities of querystrings that are built into asp, and a custom querystring script that i built into it as well. http://xearosphere.com/index
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.