The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. January 07, 2009, 01:01:29 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Mod_Rewrite - RedirectMap - http.conf on IIS  (Read 1389 times)
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« on: September 12, 2008, 05:33:57 AM »

Hey all,

I'm hoping to tap in to the collective genius that is this forum to help me out with developing a quick rewrite rule/map on... wait for it... on IIS 6.

Unfortunately (I'd say luckily) I've never managed an IIS server so I'm afraid I don't really know what I'm talking about - plus my server management experience is limited anyway, however the so called web developers I've got doing some work for me seem to need quite alot of direction on how to achieve a standard rewrite map to migrate an old site to a new site.

Anyways, enough moaning. I've got them to implement this - http://www.helicontech.com/isapi_rewrite/ - which lets me use cloned Apache Mod_Rewrite functionality, however as I'm using the free version (http://www.helicontech.com/isapi_rewrite/doc/litever.htm) I can only use the http.conf file, and I've only ever worked at the .htaccess level to date.

I'm certain it's possible to achieve what I need, I'm just hoping someone can help me out with creating the file.

The server hosts several websites so I need to ensure that any config I apply only applies to a specified domain. I had hoped just to do something like the following to test them out.

# Ensure that Rewrite engine is turned on
RewriteEngine on
 
# Test redirect
# Should cause a 301 header to be sent, redirecting sample
RewriteRule ^http\:\/\/my-domain\/my-test-url-that-does-not-exist\.html$ http\:\/\/my-domain\/index.htm [R=301,L]

But I can't quite figure it out how to get it working let alone the full rewrite map I'd like to create

I don't have access to <VirtualHost>, <Directory>, <DirectoryMatch>, <Files>, <FilesMatch>, <Location> and <LocationMatch> tags.

I realise this is a bit of a mixed bag, Windows / Mod_Rewrite but I'd apprecaite any assistance anyone can provide! I'm tearing my hair out as I don't have a dev environment to test on and the web dev agency won't give me access to their server to play! Bah!

Its entirely plausible that this little lot doesnt make sense, let me know if i need to clarify anything.

Cheers,

DM
Logged
Bompa
Administrator
Expert
*****
Offline Offline

Posts: 219


View Profile WWW
« Reply #1 on: September 12, 2008, 07:04:12 AM »

If you want to send the entire domain to the root of the new domain,
it would be something like this:

RewriteRule ^.*$ http://my-new-domain.com/index.htm [R=301,L]

If you want to redirect page to page, it can get hairy

RewriteRule ^(.*)$ http://my-new-domain.com/$1 [R=301,L]

My rewrite skills have been declining lately, but that is close and the
real genius' will be along shortly.

Otoh, I have never done this in the httpd.conf file.  LOL

you better wait for the other guys

Bompa


Logged

perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #2 on: September 12, 2008, 08:53:58 AM »

Yikes, what a Charlie Foxtrot.

OK: First off, without the VirtualHost directive, how will you assign rewrite behavior just to a single site? That's pretty vital.

The way to see if a URL doesn't work is with the -f (is file) flag.

RewriteCond %{REQUEST_URI}  !-f
RewriteRule  ^(.*)$  http://www.someplaceelse.com/index.html [R=301,L]

Hope that helps. There's little difference between httpd.conf and .htaccess except when in the processing chain that they occur (and of course, directives that can, therefore, be called). Almost 100% of the time, of a rewrite instruction works in htaccess then it will work in httpd.conf - but the reverse is not always true. I can pull a LOT more off by putting my rewrites in httpd.conf than can be done in a simple htaccess.


Logged

If I can't be Mr. Root then I don't want to play.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #3 on: September 12, 2008, 09:19:39 AM »

Thanks for the reply Perk - your dead right this situation is a mess and is incredibly frustrating.

OK: First off, without the VirtualHost directive, how will you assign rewrite behavior just to a single site? That's pretty vital.

This was where I was hoping for a little help - I was wondering if its possible to do some kind of rewrite condition at server level to decide whether the rewrite rules should be applied? Bearing in mind that I don't really know how this damn Windowz box is set up, I was hoping for something at a global level, which is all I appear to have access to, that could test incoming Domain in the request string, and then apply a rewrite map on the back of that. Make sense? Possible?

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #4 on: September 12, 2008, 12:19:54 PM »

Well, if you know that domains that the box will be receiving, then you can make the first condition ALWAYS about the domain.

Unfortunately, this will add a lot of processing to every single web call, but it can be done.

For example,

RewriteCond  %{HTTP_HOST}   mydomain.com
RewriteCond  {other stuff}
RewriteCond  {other stuff}
RewriteRule   {do something}

In this little example, since RewriteCond is an AND list by default, you're stating that IF the domain is (the one you want) then evaluate the rest of the rules. So you'd essentially need to ask this question in front of everything that you wanted to do.

You could, however, cut down on quite a bit of work by adding something in the beginning that says, if the URI ends in .jpg or .jpeg or.gif or .png or .css or .js then stop all processing and let it through... perhaps adding "if the file exists." Then you'd only process your big list of rewrite stuff for pure HTML calls, rather than calls for support graphics and files.
Logged

If I can't be Mr. Root then I don't want to play.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #5 on: September 12, 2008, 04:21:33 PM »

Just to make it clear to everyone, ISAPI rewrite is SIMILAR to mod-rewrite, but not the same. alot of the directives are assumed making it very easy to work with in an IIS environment.

@DM I have MANY YEARS of experience with isapi rewrite from helicon, and ran my seospam empire under it for a long time, though none recent. So i will take a stab. Perk is approaching it from a mod-rewrite POV which although its a valiant effort, it's worth dick Wink (sorry buddy) Mostly because there is alot of stuff in the module that makes it 'look like' it is apache-mod-rewrite, but it isnt. though briefly skimming the docs again, it looks like they made some changes... so who knows.

so...

The single http.conf is fine, and frankly, is how you would want to do it anyway if all the sites are related. if not, it can get confusing, but thats your problem for using the free version and can be solved with the pay version of course.

so first off, can you tell if ISAPI rewrite is even running at all? assuming you followed the setup, and read all the bits about if its a 64bit system and dealing with 64bitIIS, you should see an entry under the global site in IIS admin (the main web root of the tree in the admin panel, in the property pages for that).

Can you even get a simple rewrite to work? obviously it will redirect any request to google. If it doesn't work, your not setup right, end of story.
Try this:
RewriteEngine on
RewriteRule .* http://google.com [R,L]

Also, just take note of something VERY IMPORTANT. IIS caches ISAPI lookups, or at least isapi-rewrite does. So you need to refresh the page 2 times, before you will know if a rule is working.... ghey i know, but I think its because it moves the date compare to AFTER the processing is complete, to not get in the way and slow things down. Makes sense, but still caused me ALOT of grief when i first played with it.

if it does work, post and let me know, and i will tackle the next bit.
if not, fix yer busted ass shit.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #6 on: September 12, 2008, 05:47:07 PM »

Perk is approaching it from a mod-rewrite POV which although its a valiant effort, it's worth dick Wink

ROFLMAO ROFLMAO ROFLMAO ROFLMAO
Logged

If I can't be Mr. Root then I don't want to play.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #7 on: September 15, 2008, 03:51:26 AM »

Thanks for the feedback guys, much appreciated.

Unfortunately the web development company won't implement your test slution Nuts because there are other sites hosted on the server!

If I were to use Perks method to filter out domain name and then apply a generic redirect would that work as a starting point?

If I need to go down the route of the paid version I will, I'm just trying to avoid it for now.

Cheers,

Steve
Logged
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #8 on: September 15, 2008, 06:34:56 AM »

So you dont have direct access? thats probably part of the issue. they probably just "installed it" and read nothing.

ok then instead try this, which is only for your domain.

RewriteEngine on
RewriteRule .*yourdomain\.com http://google.com [R,L]

i dont think you need the http in front of your domain, but if that doesnt work, do
RewriteEngine on
RewriteRule http\:\/\/.*yourdomain\.com http://google.com [R,L]

Logged
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #9 on: September 18, 2008, 03:40:26 AM »

Sorry to keep dragging this thread up with delayed responses, it's like walking in tar trying to get things done with external developers - or at least the ones I'm working with currently.

I've decided to bypass them for now and start working on a local copy of IIS 5.1 (the Windows XP version), based on your comments so far I've managed to redirect all and add a redirect condition for hostname, but I can't get it to work for subdomains currently.

The story so far...

Code:
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.56

# Ensure that Rewrite engine is turned on
RewriteEngine on
 
# Test redirect
# Should cause a 301 header to be sent, redirecting localhost to Google.com
RewriteEngine on
RewriteCond  %{HTTP_HOST} localhost
RewriteRule ^(.*) http://google.com [R=301,L]

Whenever I attempt to append a subdomain to this, so that only test.localhost redirects for example, it bails out on me.

Any ideas?

Cheers,

DM
Logged
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #10 on: September 18, 2008, 07:31:07 AM »

hmm, you shouldnt need this
RewriteCond  %{HTTP_HOST} localhost

thats saying that you should only run the following RewriteRule, if the host is localhost.
this means the following rule wont run if you have test.localhost (i think).
but its unneccesary, because you can put the Cond inside the rule in this case. but i guess its a preference thing.
you also dont need the ^, its redundant in this case, since you are testing the domainname.
and you dont currently need to capture so you dont need the parens.
just some niggles to know about.

so do either:
RewriteCond  %{HTTP_HOST} .*localhost
RewriteRule ^(.*) http://google.com [R=301,L]
OR just this for now
RewriteRule .*localhost.* http://google.com [R=301,L]

the single line rule will match
testlocalhostaaaaaa
localhost
localhost/dir/dir
test.localhost
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #11 on: September 18, 2008, 08:00:32 AM »

Personally, I'd set up a new domain, like "tester" in the hosts file of a client machine, and then add tester.com, www.tester.com, prototype.tester.com and such to the webserver configuration, then do my rewrite tests with that, because localhost is rather special - not entirely a reserved word, but it has importance in places that might dick with your testing.
Logged

If I can't be Mr. Root then I don't want to play.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #12 on: September 18, 2008, 08:25:48 AM »

Personally, I'd set up a new domain, like "tester" in the hosts file of a client machine, and then add tester.com, www.tester.com, prototype.tester.com and such to the webserver configuration, then do my rewrite tests with that, because localhost is rather special - not entirely a reserved word, but it has importance in places that might dick with your testing.

Yeah I think it's doing something like that. Plus I think I'm suffering from a situation where subdomains are not actually being processed by the server i.e. http://test.localhost/ - both of the examples you provide Nuts don't resolve.

Any ideas on how you go about adding 'host names' to an IIS 5.1 server? :s Somthing to do with an lmhosts file sounds familiar? *mutters* Bloody M$ *mutters*

Thanks for the advice guys.

DM
Logged
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #13 on: September 18, 2008, 09:06:48 AM »

yea the file is at
C:\Windows\System32\drivers\etc
its called hosts

add entries like

192.168.1.60   test.com
192.168.1.60   www.test.com

of course you need a matching host under IIS as well.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #14 on: September 18, 2008, 09:24:34 AM »

yeah, actually 2 different topics there: first, creating a virtual host to answer to <the test domain> and then adding <the test domain> to your hosts file so you can call it out from a browser. Doesn't have to be all on the same machine.

Side note, this is precisely how I do testing before I have control of someone's domain... I'll just set Apache up to answer to it, then put the domain in my hosts file and it *looks* like production to both systems, even though no one else can see it that way.
Logged

If I can't be Mr. Root then I don't want to play.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!