Forum Moderators: phranque

Message Too Old, No Replies

Help with rewriterule?

         

Lubox

4:36 pm on Sep 23, 2004 (gmt 0)

10+ Year Member



We are currently using IIS as web server, but this has become too unstable. I have to prove a concept (?) to my bosses about switching from IIS to Apache. So I have for the first time installed Apache (on windows), and need some help in a quick rewriterule. We are using an isapi dll on our server, which we cannot use with apache: I have tried, but it won't work. Anyways, this dll has a "sister" for the apache; a cgi.exe which will do exactly the same. That is working very well. The only thing I would have to do before showing that the switch from IIS can be done easily, is to rewrite old calls to the isapi dll to the new .exe.
Our users use for example the following url:
[ourdomain.com...]
I need a rewriterule that changes this to
[ourdomain.com...]

Edit: the Service and the JustAParam can be anything and there can be a lot of parameters, this was of course just an example :)

Can someone please help me with that? I promise I will learn this if we switch to Apache :)

Thanks
Lubox

jdMorgan

5:06 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lubox,

This is actually a very simple rule, and I hope you'll give it a try. See the references cited in our charter [webmasterworld.com], especially the Rewriting Guide.

Based on your description, all you need to do is to detect /scripts/uwisapi.dll and replace it with /cgi-bin/uwcgi.exe
The query string will not need any extra work; It will pass through mod_rewrite unchanged unless you take steps to modify it.

Jim

Lubox

5:20 pm on Sep 23, 2004 (gmt 0)

10+ Year Member



I think I got it using this:

RewriteRule ^/scripts/uwisapi.dll(.*)$ [ourdomain...]

It's working on my tests at least ..

Thanks
Lubox

Birdman

5:30 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pretty good Lubox! I would only make a couple minor changes.

RewriteRule ^/scripts/uwisapi.dll(.*)$ [ourdomain...]

1) I the left side of the rule, you don't need the first slash.

2) Also in the left side, you are backreferencing(surrounding with parens) when you don't need to. When you use parens, it saves the characters matched for use in the right side. You would use $1 to call it in the right side.

3) On the right side of the rule, you don't need to use an absolute URL unless you are redirecting to another domain.

So here it is after the changes:

RewriteRule ^scripts/uwisapi.dll$ /cgi-bin/uwcgi.exe [L]

Regards,
Birdman

jdMorgan

5:36 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very close. However, you don't need the (.*), since you are not creating a back-reference, and the query string is not part of the URL that RewriteRule examines (it is handled separately). Also, if you want an external redirect, you probably want a permanent (301) redirect:

So this should work fine:


RewriteRule ^/scripts/uwisapi.dll$ http://ourdomain/cgi-bin/uwcgi.exe [R=301,L]

The [L] flag tells mod_rewrite to do the redirect immediately, and not process any further rewriterules. You should use [L] unless you know you have a reason not to.

You also didn't say whether you want an internal "silent" rewrite, or an external redirect. If you want an internal rewrite, use:


RewriteRule ^/scripts/uwisapi.dll$ /cgi-bin/uwcgi.exe [L]

The choice between an internal rewrite and an external redirect depends on whether you want search engines to up update links to the old URL. If so, use the external redirect.

<added>
> 1) In the left side of the rule, you don't need the first slash.

The leading slash will be required for use in httpd.conf. It is not needed if the code is used in an .htaccess context. In either case, if it's wrong, the code won't work.
</added>

Jim

[edited by: jdMorgan at 5:39 pm (utc) on Sep. 23, 2004]

Birdman

5:38 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Jim, am I wrong when I said that you don't need the first slash? I see you have it in your example as well.

Lubox

7:13 am on Sep 24, 2004 (gmt 0)

10+ Year Member



I can't find anything about redirecting HTTPS-requests to HTTP-requests. Is this possible, and if so, do I need a ssl-certificate on my server? I guess I *really* shouldn't change it, so maybe I should redirect to another server with a installed certificate..

Thanks
Lubox

Lubox

12:59 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Ok, never mind my last post - I figured it out.

However, I reinstalled Apache, and edited the httpd.conf as it was before with this rewriterule:

RewriteEngine on
RewriteRule ^/scripts/uwisapi.dll$ /cgi-bin/uwcgi.exe [L]

Now it fails. It says 404 not found, and the error.log says: "[Fri Sep 24 15:04:20 2004] [error] [client xx.xx.xx.xx] File does not exist: D:/Apache2/htdocs/cgi-bin"

Why is it trying to find it in /htdocs/cgi-bin? cgi-bin is not there. It's in D:/Apache2/cgi-bin and if I try the url which it should be rewritten to, everything is ok. I have ScriptAlias /cgi-bin/ "D:/Apache2/cgi-bin/"

Thanks
Lubox

Lubox

6:07 am on Oct 20, 2004 (gmt 0)

10+ Year Member



Hi again

Sorry for bumping this old thread, but it saves me some new explaining. I have not been able to fix the latest challenge with my rewrite. If I add our domain on the right side (http://ourdomain/cgi-bin/uwcgi.exe) it seems to work, but I want to rewrite both http and https and am not sure how to do this.

The log looks like this by the way:
#*$!.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (2) init rewrite engine with requested uri /scripts/uwisapi.dll
xxx.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (3) applying pattern '^/scripts/uwisapi.dll$' to uri '/scripts/uwisapi.dll'
xxx.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (2) rewrite /scripts/uwisapi.dll -> /cgi-bin/uwcgi.exe
xxx.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (2) local path result: /cgi-bin/uwcgi.exe
xxx.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (2) prefixed with document_root to D:/Apache2/htdocs/cgi-bin/uwcgi.exe
xxx.xx.xxx.x - - [20/okt/2004:07:56:58 +0200] [ourdomain.com/sid#23bc18][rid#28c3060/initial] (1) go-ahead with D:/Apache2/htdocs/cgi-bin/uwcgi.exe [OK]

So I want to get rid of that "prefixed with document_root" I guess..

Thanks
Lubox

Lubox

10:12 am on Oct 20, 2004 (gmt 0)

10+ Year Member



Hi again

Hope you don't mind me talking to myself in here, but I'll try to be gentle with myself ;) (!)

I got my rewrite rule to work for http, by using [PT,L] (instead of just [L]) in the end of it. I'm not sure why it's working now, but it seems like this tells apache to remember to continue to handle the scriptalias....or something

Anyhow, the same URL with HTTPS instead of HTTP is not working (the URL is working directly, yes). Do I have to have another rewriterule for HTTPS-connections?
This is how it looks now:
RewriteRule ^/scripts/uwisapi.dll$ /cgi-bin/uwcgi.exe [PT,L]

Thanks
Lubox

jdMorgan

2:24 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lubox,

For some reason, we didn't see your thread get updated and bumped to the top of the list when you posted.

You need to fix the problem with your ScriptAlias directive before proceeding. Rather than continue to put patches on top of this problem, it would be better to figure out why rewrites end up with the /cgi-bin path prepended. Nothing happens on Apache by "magic" so there is an underlying error here.

Jim

Lubox

12:10 pm on Oct 22, 2004 (gmt 0)

10+ Year Member



Hi

Ok, it seems I got it going now. I had to have a rewrite-rule in the virtual host for the SSL-stuff (*cough*). The PT had to be there because I was using mod_alias.

Thank you for your help with this. On Monday I will switch from IIS to Apache if the remaining tests are ok ;)

The next thing I have to figure out is how to make compatible web services for the ones I have on IIS. But that is no big deal yet...

Lubox