473,765 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rewrite rule

Hello everybody

In apache I used a feature called a "Rewrite rule" inside a .htaccess
file to process the URL :
i.e. http://www/mypage.html =http://www/page.php?page=mypage

Now I'd like to do a similar action on a IIS server with ASP (not
..net)...

Can anyone tell me how you can do this ?

thanks in advance!
Mathew

Dec 31 '06 #1
5 3609
Lupus wrote on 31 dec 2006 in microsoft.publi c.inetserver.as p.general:
Hello everybody

In apache I used a feature called a "Rewrite rule" inside a .htaccess
file to process the URL :
i.e. http://www/mypage.html =http://www/page.php?page=mypage

Now I'd like to do a similar action on a IIS server with ASP (not
.net)...

Can anyone tell me how you can do this ?
Meseems you will have to explain what it does.
In general we do not use apache.

Possibly this is the effect you want:

========http://www/mypage.html ============

<% ' vbscript
response.redire ct "/page2.php?page= mypage"
%>

=============== =============== =============

If you want to redirect from nonexisting pages,
I suggest from a specified [even nonexisting] directory,
you could write code in te dedicated 404.asp page
redirecting those calls and selecting the pagename as
querystring.

However, this can be better done as a server.transfer ,
where the original virtual calling string
is available in a session variable.
[do not forget to clear the session variable
after extraction of the page name,
or do not use it elswhere in the session]

============= /404.asp =============== =====
<%
qstr = lcase(Request.S erverVariables( "QUERY_STRING") )
if instr(qstr,":80/virtualdirector y/")>0 then
session("qstr") =qstr
server.transfer "/anydirectory/page.php"
end if
%>
<html>
......
This is our 404 page.<br>
The page you want:<br>
<%=qstr%><br>
does not exist.
</html>
=============== =============== ============

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 31 '06 #2

"Evertjan." <ex************ **@interxnl.net wrote in message
news:Xn******** ************@19 4.109.133.242.. .
Lupus wrote on 31 dec 2006 in microsoft.publi c.inetserver.as p.general:
>Hello everybody

In apache I used a feature called a "Rewrite rule" inside a .htaccess
file to process the URL :
i.e. http://www/mypage.html =http://www/page.php?page=mypage

Now I'd like to do a similar action on a IIS server with ASP (not
.net)...

Can anyone tell me how you can do this ?

Meseems you will have to explain what it does.
In general we do not use apache.

Possibly this is the effect you want:

========http://www/mypage.html ============

<% ' vbscript
response.redire ct "/page2.php?page= mypage"
%>

=============== =============== =============
What exactly would you expect this to do in an .HTML file? Unless you
mapped the .html extension to asp.dll, to process files with that extension
as server-side script, the correct answer would be "nothing".
-Mark
If you want to redirect from nonexisting pages,
I suggest from a specified [even nonexisting] directory,
you could write code in te dedicated 404.asp page
redirecting those calls and selecting the pagename as
querystring.

However, this can be better done as a server.transfer ,
where the original virtual calling string
is available in a session variable.
[do not forget to clear the session variable
after extraction of the page name,
or do not use it elswhere in the session]

============= /404.asp =============== =====
<%
qstr = lcase(Request.S erverVariables( "QUERY_STRING") )
if instr(qstr,":80/virtualdirector y/")>0 then
session("qstr") =qstr
server.transfer "/anydirectory/page.php"
end if
%>
<html>
.....
This is our 404 page.<br>
The page you want:<br>
<%=qstr%><br>
does not exist.
</html>
=============== =============== ============

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jan 1 '07 #3
Mark McGinty wrote on 01 jan 2007 in
microsoft.publi c.inetserver.as p.general:
>========http ://www/mypage.html ============

<% ' vbscript
response.redir ect "/page2.php?page= mypage"
%>

============== =============== ==============

What exactly would you expect this to do in an .HTML file?
Unless you
mapped the .html extension to asp.dll, to process files with that
extension as server-side script, the correct answer would be
"nothing".
True. My mistake, read: http://www.??.??/mypage.asp
IIS can remap [about?] any extention to be read by the asp interpreter.
>============ = /404.asp =============== =====
<%
qstr = lcase(Request.S erverVariables( "QUERY_STRING") )
if instr(qstr,":80/virtualdir/")>0 then
session("qstr") =qstr
server.transfer "/anydirectory/page.php"
[..]
The .php, could be anything, I prefer page.asp
>end if
%>
However, my real [in my view] answer was this use of 404.asp.
The extention of the nonexisitng [=virtual] pages does not matter here,
the asp interpereater is always "on".

The page.asp could be something like this:
[on my site, even Google sees this page as 110 different ones]

=========== /anydirectory/page.asp =============== =
<html>
<head>
.....
</head>
<body>
<% if instr(session(" qstr"),"/virtualdir/xxx.html")>0 then %>
<b>This</bis the content of xxx .............
<% elseif instr(session(" qstr"),"/virtualdir/blah.qrs")>0 then %>
<b>This</bis the content of blah .............
<% elseif instr(session(" qstr"),"/virtualdir/otherext.asp")> 0 then %>
<b>This</bis the content of <%=session("qst r")%>:
..............
<% else %>
Page not found [404]
</body>
</html>
<%
session("qstr") = ""
response.end
end if
session("qstr") = ""
%>
<br>General footer [except for not found 404] .........
</body>
</html>
=============== =============== =============== ========

To make it really perfect, you would have to make dynamic headers
of the 200 and 404 kind.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 1 '07 #4
Hello all,

Thanks for all your responses...

The thing I do on apache is a very common trick which is quite easy to
set up. I'm not sure it has to be so difficult on IIS (at least, I hope
so)

It doesn't really have a functional purpose, it can only make the URL
more attractive or easier to use.

This is the code I need to put into .htaccess file :
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ index.php?setpa ge=$1 [nc]
</IfModule>

Result: each *.html request in the URL is "translated " discretely into
index.php?setpa ge=pagename
In my case, index.php processes CMS-based pages and opens the page with
the name "pagename"

I works as good without the htaccess code, but you'll get this in the
URL :
http://www.domain.com/index.php?setpage=aboutus
http://www.domain.com/index.php?setpage=contactus
http://www.domain.com/index.php?setpage=guestbook

Using the rewrite rule, the URL looks like this :
http://www.domain.com/aboutus.html
http://www.domain.com/contactus.html
http://www.domain.com/guestbook.html
I'll give another example :
Take for example: http://www.php.net/strptime

You might think that the webbrowser has a directory "strptime" which
responds, but in reality it's the "rewrite rule" which converts the URL
discretely into http://be2.php.net/manual/en/function.strptime.php

Result : If I need the reference page of the strlen-function in PHP, I
know I can type "php.net/strlen" and I don't need to type
be2.php.net/manual/en/function.strlen .php.

Yet another example :
http://www.hotscripts.com/Detailed/50145.html

hotscripts is a databasedriven website, so I presume they don't need to
create a .html file for each item in the database. The above URL is
probably translated into something like : detail.php?item =50145.

I'm using a commercial webhosting server, and I don't think I can
access the settings for 404 errors. I was hoping IIS has a similar way
for doing URL rewriting...

Kind regards, and Happy newyear !
Mathew
Evertjan. schreef:
Mark McGinty wrote on 01 jan 2007 in
microsoft.publi c.inetserver.as p.general:
========http://www/mypage.html ============

<% ' vbscript
response.redire ct "/page2.php?page= mypage"
%>

=============== =============== =============
What exactly would you expect this to do in an .HTML file?
Unless you
mapped the .html extension to asp.dll, to process files with that
extension as server-side script, the correct answer would be
"nothing".

True. My mistake, read: http://www.??.??/mypage.asp
IIS can remap [about?] any extention to be read by the asp interpreter.
============= /404.asp =============== =====
<%
qstr = lcase(Request.S erverVariables( "QUERY_STRING") )
if instr(qstr,":80/virtualdir/")>0 then
session("qstr") =qstr
server.transfer "/anydirectory/page.php"
[..]

The .php, could be anything, I prefer page.asp
end if
%>

However, my real [in my view] answer was this use of 404.asp.
The extention of the nonexisitng [=virtual] pages does not matter here,
the asp interpereater is always "on".

The page.asp could be something like this:
[on my site, even Google sees this page as 110 different ones]

=========== /anydirectory/page.asp =============== =
<html>
<head>
....
</head>
<body>
<% if instr(session(" qstr"),"/virtualdir/xxx.html")>0 then %>
<b>This</bis the content of xxx .............
<% elseif instr(session(" qstr"),"/virtualdir/blah.qrs")>0 then %>
<b>This</bis the content of blah .............
<% elseif instr(session(" qstr"),"/virtualdir/otherext.asp")> 0 then %>
<b>This</bis the content of <%=session("qst r")%>:
.............
<% else %>
Page not found [404]
</body>
</html>
<%
session("qstr") = ""
response.end
end if
session("qstr") = ""
%>
<br>General footer [except for not found 404] .........
</body>
</html>
=============== =============== =============== ========

To make it really perfect, you would have to make dynamic headers
of the 200 and 404 kind.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 1 '07 #5
Lupus wrote on 01 jan 2007 in microsoft.publi c.inetserver.as p.general:

[Please do not toppost on usenet]
hotscripts is a databasedriven website, so I presume they don't need to
create a .html file for each item in the database. The above URL is
probably translated into something like : detail.php?item =50145.
I don't think you should expect all nice quirks of one system to be
implemented in the other. If there are no diferences, what would be the
sense of different systems, but the pricing?

I think I showed you that is can easily be done in ASP code.

This NG really is not about IIS, there are other NG's for that, but about
ASP, so I showed you the, I mean an, ASP way.
I'm using a commercial webhosting server, and I don't think I can
access the settings for 404 errors. I was hoping IIS has a similar way
for doing URL rewriting...
My sites on my webhost have the possibility of a dedicated 404.asp page.
I make extensive use of them.

If you choose a webhost, choose a good one within your means, methinks

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3990
by: jbj | last post by:
I am trying to make a javascript function that can rewrite javascript rules dynamically (no, not the style tag of an individual element, but the actual rule in the <head> portion of the document). I have this code working in Mozilla (so I imagine Netscape browsers) but it gives me an error with IE. A few questions about it: First, here is my current code: <code> function expand(show)
4
1773
by: Stefan Reiter | last post by:
Hi, I got a totally dynamic website, and to improve my search engine results, I would like to use mod rewrite. From what I've understood so far, I have to put the necesarry lines into my htacess file, right? Anyway, I read some tutorials, but I can't quite grasp how to do it in my case -
0
1352
by: darrel | last post by:
We're using ISAPI rewrite on our site. We have a URL that looks like this: /district/2/ that gets rewritten to: /default.aspx?siteID=2
2
2075
by: sri_san | last post by:
Hello group, After going through a nice article at MSDN(http://msdn2.microsoft.com/en-us/library/ms972974.aspx), I was able to make the URL rewrite working except for coming up with a generic rule using regular expressions. Any URL with the format http://servername/dir/folder30/default.aspx has to be converted to http://servername/default.aspx?id=30
1
3073
by: soniamuk | last post by:
i am facing a typical issue with apache where i have a filter context(written in c++) which pulls information from apache server. in this process when i am trying to fetch an url where rewrite rule of apache is in picture the fethced value is not correct. say the rule i am using in rewrite.conf is RewriteRule ^/ows/printenv$ http://10.152.70.206:9999/cgi-bin/printenv.pl?map=public.map what is seen is if i access ^/ows/printenv apache...
2
1588
by: fredBH | last post by:
Hi everyone! I need some help to configure my rewrite rule for these url : http://www.test.com/start forward to http://www.test.com/action/start.php http://www.test.com/user/delete/1 forward to http://www.test.com/action/user.php?action=delete&id=1 http://www.test.com/acao/community/post/3 forward to http://www.test.com/action/community.php?action=post&id=3
4
1555
by: adamjblakey | last post by:
What would be the correct MOD Rewrite rule for this: http://www.website.co.uk/building-an...ices/cheshire/ I thought it would be: Code: RewriteRule ^building-and-construction/(+)/(+)/$ results.php?item=$1&other_item=$2
1
3498
by: mazdotnet | last post by:
Hi all, I've installed the new Microsoft URL Rewrite Module for IIS 7.0 http://www.iis.net/downloads/default.aspx?tabid=34&i=1691&g=6 on both my laptop (Vista Home Premium) and my desktop (Vista Ultimate). I'm running my sites on IIS instead of the ASP.NET server. If I call my site using http://localhost in the browser, it works fine. However, as soon as I run it from within Visual Studio 2008 in
0
1934
by: andrewteg | last post by:
I have an application that is installed as http://domain.com/folder/ and serves pages as http://domain.com/folder/index.ext/parent/child/ and I'm trying to remove index.ext from the URL so that http://domain.com/folder/parent/child/ would work as well. Does anyone have an idea on what rewrite rule I would need? I tried: RewriteRule ^(.*)$ index.cfm%{REQUEST_URI} but that sends it to /folder/index.ext/folder/parent/child/ instead... ...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.