Complex redirects with .htaccess


#1

I think I’ve posted this one before, but I haven’t found a good solution yet. I’m hoping some fellow dreamhosters have some ideas:

I want to set up some URL rewrite scheme in my .htaccess file in order to remove parts of the URL (marked red below).

My site is driven by a script in the /bin/ folder, and the script reads a folder and a filename: [color=#00CC00][color=#CC0000]/bin/view[/color]/Main/WebHome[/color] = “[color=#CC0000]view[/color] the [color=#00CC00]WebHome[/color] page in the [color=#00CC00]Main[/color] folder”. This means that my URLs are long and ugly: http://g-b.dk[color=#CC0000]/bin/view[/color]/Main/WebHome

I want to be able to type: [color=#00CC00]http://g-b.dk/Main/WebHome[/color]
and then the server would pick: [color=#00CC00]http://g-b.dk[color=#CC0000]/bin/view[/color]/Main/WebHome[/color]
but without diplaying the red bit.

So I’m looking for something that can rewrite the request-url to insert [color=#CC0000]/bin/view[/color] after the domain. It’s not that simple though:
– I might want to have some URLs like [color=#00CC00]http://g-b.dk/gallery[/color] without activating the rewrite.
– If I’m requesting something that already has the [color=#CC0000]/bin/view[/color] part, then it shouldn’t be inserted a second time.
– There are other scripts besides [color=#CC0000]/bin/view[/color], like for example [color=#CC0000]/bin/attach[/color] and [color=#CC0000]/bin/edit[/color]. All scripts are in the [color=#CC0000]/bin/[/color] folder, though.

The folder name and filename always begin with an uppercase letter, if it’s any help, while normal links like /gallery are lowercase. I’ve tried to read up on the magic world of RegEx and RewriteRules but I don’t grasp it yet. If it’s any help, then


TorbenGB
Try out DreamHost with a free WebID /// Compare plans


#2

I could not be thinking about this enough, but would this do the trick?

RewriteEngine On
RewriteRule ^([A-Z].*) /bin/view/$1

(placed in an .htaccess in the root of the web site.)


#3

So simple. So elegant. Thanks Mark! Now I can leave out the [color=#CC0000]/bin/view[/color] part of URLs and it still shows the right page, and the browser still doesn’t show the [color=#CC0000]/bin/view[/color] part. Great! This addresses 95% of what I want to achieve.

When I click links in the pages, then the [color=#CC0000]/bin/view[/color] part appears. How should another RewriteRule look if I want to hide that in these as well? I imagine that it should look for the [color=#CC0000]/bin/view[/color] part and then remove that from the URL.


TorbenGB
Try out DreamHost with a free WebID /// Compare plans