article

Extended Urls / Fake Urls

Email
Submitted on: 1/7/2015 4:56:00 AM
By: Mr.Miagi (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 1657
 
     :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.

 
				

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


 There are no comments on this submission.
 

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.