Kuro5hin.org: technology and culture, from the trenches
create account | help/FAQ | contact | links | search | IRC | site news
[ Everything | Diaries | Technology | Science | Culture | Politics | Media | News | Internet | Op-Ed | Fiction | Meta | MLP ]
We need your support: buy an ad | premium membership

Does anyone use mod_rewrite?

By eries in Technology
Sun Oct 22, 2000 at 09:39:01 PM EST
Tags: Software (all tags)

I've been using Apache's mod_rewrite module for some time now. It's incredibly powerful, and for those that don't already know, can do almost any kind of URL <-> filename mapping from within an Apache process. Now, I've tried to get developers in various projects (including our own illustrious Scoop) to use mod_rewrite, but there seems to be resistance, because mod_rewrite is arcane and difficult to use. Does anybody else out there actually use it?

Now, I've read both the official docs and Ralf S. Engelschall's excellent URl Rewriting Guide, but I'm curious if anyone else knows of any other resources for mod_rewrite out there.

Let me give one example of how mod_rewrite is useful. In Scoop, we have URLs to access a particular section/topic/author/etc. Currently, they look like this:


For several reasons (such as enabling search engines to crawl your pages, but see for others) you might want to have these URLs to be a bit more user-friendly:


Using mod_rewrite, this can be done easily, quickly, and transparently to both the user and, most importantly, the Scoop software itself. All it takes is a few modifications to your .conf file.

Still, despite its obvious advantages, there still is a lot of fear and uncertainty about using mod_rewrite. Why?


Voxel dot net
o Managed Hosting
o VoxCAST Content Delivery
o Raw Infrastructure


Related Links
o Scoop
o Kuro5hin
o Scoop [2]
o official docs
o URl Rewriting Guide
o for others
o Also by eries

Display: Sort:
Does anyone use mod_rewrite? | 23 comments (22 topical, 1 editorial, 0 hidden)
Arcane? (2.52 / 23) (#1)
by Signal 11 on Sun Oct 22, 2000 at 06:44:50 PM EST

Considering what some people do to get their gnome/E desktop looking right, or the hoops we jump through tweaking fetchmail and sendmail... or god forbid, someone who uses Emacs, "arcane" is hardly an argument in the unix world.

It's probably more along the lines of "I have too much to do right now, I can't learn about that.. besides, it already works".

People spend so much time tweaking and configuring UNIX that they have little time do to what they set out to do. That's where the resistance is coming from, not its "arcane-ness".

Society needs therapy. It's having
trouble accepting itself.

...and so it starts... (2.78 / 28) (#5)
by BOredAtWork on Sun Oct 22, 2000 at 08:08:06 PM EST

...here we go, folks, brace yourselves for another Social Experiment!

First, we had this gem, where the experiment began by calling 2600 "idiots," as well as suggesting that they're an example of "online activism at its worst," disorganized, and just beating their chest rather than doing anything productive. This, contrary to previous Signal11 posts where he says that the DeCSS battle is critically important, and congratulates 2600 for being heroic by standing up for digital freedom. My favorite (after 30 seconds of searching) is the first post on this article, where everyone's favorite social researcher said (in regards to the MPAA lawsuit against 2600), and I quote, "I want to get my name on this lawsuit too... I figure with several thousand defendants we can't lose. :)" Not exactly a strong condemnation of 2600 or their actions. Sure sounds like your tune has changed...

Next, we had The First Edition of Signal 11's Weekly K5 Column, which was (thankfully) voted out of existance within an hour. Siggy wanted to get himself on the front page every Friday with a list of his favorite K5 front page stories of the week (you know, those ones which are on the front page for a week at a time anyway).

Siggy will say just about anything to either 1) pander to the audience in order to draw responses or 2) incite the audience into argument to draw responses. I think that this post, which slams KDE, GNOME, sendmail, fetchmail, Emacs, and UNIX in general is a #2.

My question is... dude, why are you so desparate for attention...? And now that you've openly admitted you'll say anything just to get a response, why should anyone give a shit what you have to say...?

You know, I really wish I didn't have this project due in 24 hours. I'd love to spend a few hours searching slashdot and k5, find how many times you've taken whatever opinion you think will get the most replies/reactions, and write up a nice article for one of the academic psychology journals about how people find their self esteem in getting replies (be it good or bad) from total strangers, and how people seek a feeling of power by doing it.

[ Parent ]

Huh? (2.75 / 8) (#10)
by Broco on Sun Oct 22, 2000 at 09:21:24 PM EST

That post didn't seem like a troll to me. He was expressing his opinion that many unix tools are very arcane difficult to learn (an opinion which I happen to share), and that therefore no one in the unix world should mind that mod_rewrite is arcane. Maybe not correct, but certainly on-topic and reasonable. Nor does it seem offensive to me: I know I spent a long time figuring out the intricacies of the apps he listed and agree that they are arcane.

Where did he "openly admit" he'd say anything for a response?

Posting on web discussion boards is Sig11's hobby, he does contribute a lot of interesting stuff, he doesn't flame, so why do you hate him so much? Are you going to start hating professional writers because they also crave people reading their work? I'd like to know where you get your self-esteem from and how it's somehow better than Sig11's way (if you're right and that's why he posts so much).

Klingon function calls do not have "parameters" - they have "arguments" - and they ALWAYS WIN THEM.
[ Parent ]

Why I detest Signal 11 (2.66 / 12) (#15)
by BOredAtWork on Mon Oct 23, 2000 at 01:06:38 AM EST

Where did he "openly admit" he'd say anything for a response? - Right here. Read it; it reads like he tried to write himself a eulogy after being martyred. Some quotes...

"Well, shortly after this I decided to test the system myself, and conducted a small-scale experiment by posting a variety of opinions and seeing how people reacted." - Yeah... this "small-scale" experiment was "small" in the sense that the Signal11 account reached around 900 Karma, and is quite possibly *the* most well known name on slashdot. Basically, you can't trust a word he says, because for months, he said ANYTHING just to get people to reply. And when Rob Malda put in the Karma Cap to take away his measuring stick of Greatness, he took his toys, and left. And came here.

"On practically every article that I could come up with an opinion on, I posted to. Some of them were fine works of literary art. Others were little more than OOG_THE_CAVEMAN posts, except without the capitalization." - Once again, this isn't a "small-scale" experiment. At first, maybe he did post some insightful comments. I recall a few that were worth rereading. But in the end, all he did was take the "popular" thought, and spit it back out, in order to draw responses. Or, he took the "unpopular" thought, and trolled with it, in order to draw responses.

Posting on web discussion boards is Sig11's hobby, he does contribute a lot of interesting stuff, he doesn't flame, so why do you hate him so much? - Because he doesn't CONTRIBUTE. He has no original thought; he just spits back the thoughts of others and tells them what they want to hear in order to see his name show up. As far as I'm concerned, he's lost all credibility.

Are you going to start hating professional writers because they also crave people reading their work? - I do detest professional "writers" who don't have original thought. I'm dating an English major; you certainly can't accuse me of hating ALL professional writers. There's plenty of room in the world for columnists who just restate old ideas, but they're hardly artists, or writers. To me, a WRITER is someone who expresses an original thought, or an old thought in a new way. Signal 11 does neither; he's a hack, and a poor one at that. He's no better than E!, or Britney Spears. He says what he says simply because that's what people will react to. Britney Spears is an excellent ENTERTAINER. But she's not a musician. Signal 11 is no more a writer than she is a musician. She can't write a song or play an instrument or sing a capella without studio help, and Signal 11 is no better. At most, he's an entertainer. An amusing sideshow. "Gee, where did he troll today?"

I'd like to know where you get your self-esteem from and how it's somehow better than Sig11's way (if you're right and that's why he posts so much). - I get my self esteem from being able to have original thought and articulate it well. Gimme a week to finish up some of my school work, and I'll have an article in the submission queue. I've been working on a few for a while now. Unlike Signal 11, I value quality over quantity.

Anyways, this post may or may not have appeared to be a troll. But the sad thing is, given his past antics, nobody can tell. Given his past antics, anything he says now using that nick is always void and invalid, at least in my book. If he wants to be taken seriously, let him get a new nick. And let him put his real name with it; in the vast majority of situations, anyone with opinions that are valid will be proud to stand up behind them.

-BOredAtWork, or Dave Sracic. Take your pick.

[ Parent ]

What is your problem (2.88 / 9) (#14)
by Dacta on Mon Oct 23, 2000 at 12:49:59 AM EST

I think you need to relax a little. I didn't think Sig's post was particually special, but I didn't think it deserved that kind of personal flame attack, either.

If Signal 11 wanted to pursue social experiments, he could have done them under another nic (like BOredAtWork say... and then he could have BOredAtWork flaming Signal 11 everytime he posted. Not that I think this is true, of course)

I think rusty said it best:

If you think the story sucked. Fine. Say it. If you don't like Signal 11 for some kind of personal reason, well, basically, we don't care. Leave it at home. Thank you.

[ Parent ]
Used it last night, in fact. (3.00 / 5) (#2)
by Arkady on Sun Oct 22, 2000 at 07:06:31 PM EST

I've set up several mod_rewite based proxy servers, but I'd never used it for rewriting on the same server till yesterday. I'd just spen four hours trying to get a rather hairy URL rewriting CGI to work properly (don't ask), and realized that mod-rewrite would do what I needed without the CGI having to do anything other than fetch files.

Since I already had a rewrite-enabled binary around, it took me ten minutes to strip the rewriting code out of the CGI and add the appropriate rwriting rules to the httpd.conf file. Doh!

Turning and turning in the widening gyre
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere Anarchy is loosed upon the world.

perhaps some people... (2.66 / 6) (#3)
by mafried on Sun Oct 22, 2000 at 07:08:26 PM EST

don't use Apache? Or perhaps they do, but want to keep their code portable?

mod_rewrite would still be portable (3.00 / 3) (#4)
by Arkady on Sun Oct 22, 2000 at 07:16:03 PM EST

It's the URLs that wouls stop being consistent across Scoop sites.

The Apache rwrite, as the author points out, would only change the URLs used in the site to make them look like directory and file references, rather than CGI calls. It sould quite easily be added to Scoop in a portable manner, with just a modification of the URL construction routines (checking a preference, for example, and constructing the URLs in CGI or rewritten style based on it).

Of course, that'd all be pointless if you actually don't use Apache. ;-)


Turning and turning in the widening gyre
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere Anarchy is loosed upon the world.

[ Parent ]
obvious advantages? (2.50 / 6) (#6)
by eMBee on Sun Oct 22, 2000 at 08:11:41 PM EST

i don't see any.
the obvious thing would be to parse a directory style url in scoop directly (or in any cgi for that matter). ever looked at the PATHNAME variable? that is what's it for, to pass on pathname style urls to a cgi script.

using mod_rewrite may make sense if you need to deal with a binary cgi, or someone elses code that you don't want to touch for some reason. but if you want pathname style urls for scoop (and yes, i'd want them too) then why not fix scoop directly?

greetings, eMBee.
Gnu is Not Unix / Linux Is Not UniX

How? (2.66 / 3) (#11)
by whatnotever on Sun Oct 22, 2000 at 09:35:38 PM EST

How, other than mod_rewrite, do you cause a request like "GET /foo/bar/" to be handled by a script?

Just curious.

[ Parent ]
"GET /foo/bar" without mod_rewrite (4.00 / 5) (#16)
by Lionfire on Mon Oct 23, 2000 at 01:15:48 AM EST

It can be done by simply putting the following in /foo/bar/.htaccess
DirectoryIndex /cgi-bin/anyScript.pl

That said, I have used mod_rewrite to host subdomains without needing to organise it with my ISP. *.lostrealm.com is redirected virtual hosted to me, and mod_rewrite lets me shuffle people to the right pages:
RewriteCond %{HTTP_HOST}   ^the\.lostrealm\.com$            [NC]
RewriteRule !^the/         -                                [C]
RewriteRule ^(.*)$         /the/$1

Although the logs get a bit confusing, since they don't differentiate between www.lostrealm.com/blah and anythingelse.lostrealm.com/blah.

[ blog | cute ]
[ Parent ]
Lots of sites make minor use of mod_rewrite (3.57 / 7) (#7)
by YellowBook on Sun Oct 22, 2000 at 08:32:46 PM EST

E.g., almost all sites running Zope with Apache use mod_rewrite to rewrite urls starting in '/' to wherever the CGI or FastCGI script that feeds data to the Zserver lives. mod_rewrite is not all that arcane for doing simple things that are just a little beyond the abilities of mod_alias.

On the other hand, mod_rewrite gives you plenty of rope to hang yourself with. Once you start having complex rules or multiple rules that interact with each other, it can be very hard to tell what exactly is happening to your URLs (and where). In that way, mod_rewrite is a lot like Perl -- it can be the most expedient method of solving problems that would be much more difficult by 'conventional' means, but it is very easy to make an unmaintainable mess, often even before you've realized that you've done it.

Hello, my name is fvw and I'm a mod_rewrite user. (2.25 / 4) (#8)
by fvw on Sun Oct 22, 2000 at 08:51:48 PM EST

I do use mod_rewrite occasionally, but not if not necessary, because it's hell to figure out.

``The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.''

-- Brian Behlendorf
Apache Group

(Hmm, I now notice that quote is in the linked page as well. Oh well, it's still true).

why? (2.57 / 7) (#12)
by enterfornone on Sun Oct 22, 2000 at 10:04:09 PM EST

i think the reason why i've never considered mod_rewrite for anything is that i've never until now really understood what it does. now that it's been explained i think i might have to go and try it out

efn 26/m/syd
Will sponsor new accounts for porn.
Use it all the time (4.16 / 6) (#13)
by Pseudonym on Mon Oct 23, 2000 at 12:08:35 AM EST

I've found mod_rewrite extremely useful in conjunction with another server-side scripting or application server system. Consider, for example, a scripting system which is embedded in HTML files, such as PHP or HTML::Mason. If you want "virtual" directories (e.g. the person directory on the flagship Scoop site), simply use a rewrite:

        RewriteRule ^person/ /scripts/person-directory-handler.script

It also provides a nice hack for preventing access to files needed for serving content but which for cleanliness reasons you want to store in the htdocs directory. This recipe, for example, maps all .dat files to a different URL:

        RewriteRule ^(.*\.dat)$ /use/this/url/instead

Yes, you could do this with some SetHandler magic, too, but I find this cleaner.

Oh, it's also invaluable if you want to reorganise your site but you want old links still tol work.

sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
Most mod_perl users are probably using mod_rewrite (3.85 / 7) (#17)
by autarch on Mon Oct 23, 2000 at 09:53:42 AM EST

A very large proportion of mod_perl users are probably using mod_rewrite. Unless literally every single aspect of a site is dynamic (images included) it will pay off to have a 2-tiered Apache setup. The front side Apache server handles all static requests itself. Any requests for dynamic content can use mod_rewrite to proxy the request to a backend Apache server with mod_perl. This lets you start fewer memory hog mod_perl servers and still serve lots of clients.

See Stas Bekman's amazing mod_perl guide for more info. If you're running mod_perl and you're not doing this, then you probably have some reading to do.


mod_rewrite is evil (3.00 / 2) (#18)
by shaggy on Mon Oct 23, 2000 at 08:29:43 PM EST

I use mod_rewrite for certain things on the sites the company I work for runs. We utilize it so that we can use one cookie for all our sites. It is a very powerful tool, but is, as the docs admit, akin to playing with voodoo. I've run into some things I think may be bugs (interaction with SSL) and having non mod_rewrite and mod_rewrite vhosts in the same config file. When it works, it rocks, but it can be maddening to figure out.

Hmmm, I thought I replied to this already. (3.00 / 3) (#19)
by Inoshiro on Tue Oct 24, 2000 at 10:57:41 AM EST

Anyways, we all saw your posting on Scoop-Help. I certainly think it's a great idea. Scoop is already inherintly only portable to mod_perl based systems.. which limits it to Apache at the moment. The mod_rewrite magic would certainly make it somewhat nifty to add "smarter" navigation of the site.

The problem, of course, is one of security. The recent posting on bugtraq, and later release of Apache 1.3.14, should hammer home the point of this. The new Apache doesn't work with mod_perl (at least, it didn't when I tried to make it work yesterday).. Plus, I'd have to add documentation concerning this, and I'm a bit busy documenting other things atm. Just because your suggestion isn't immediately taken up, doesn't mean we've given up on it. Just resubmit it with more information -- it'll make our jobs easier, and remind us that this neat usage of mod_rewrite is possible.

[ イノシロ ]
no offense intended, not even a little (3.00 / 1) (#20)
by eries on Wed Oct 25, 2000 at 12:34:35 AM EST

I hope no offense was taken from my posting. I don't mean to criticize the Scoop team. It's completely understandable. My only point is that these issues make it tough to know whether this is something worth using. I didn't know about the bugtraq issue.

My main goal in writing this story was to find out if there were any other good mod_rewrite resources out there, not to criticize anybody.

Keep up the good work,

Promoting open-source OO code reuse on the web: the Enzyme open-source project
[ Parent ]

Off topic but.. (Apache 1.3.14 with mod_perl) (4.00 / 1) (#21)
by autarch on Wed Oct 25, 2000 at 11:48:41 AM EST

You need to use mod_perl 1.24_01 if you want to use mod_perl with Apache 1.3.14.

Doesn't anybody read the mod_perl mailing list?!


[ Parent ]
easier ways (2.00 / 1) (#22)
by mstevens on Thu Oct 26, 2000 at 01:01:07 PM EST

I used to use mod_rewrite....

Then I noticed it was actually easier to install and setup mod_perl, and write a trans handler in mod_perl than it was to create a rewrite rule to do what I wanted. mod_rewrite is a lovely idea, but far too hard to use.

File download (1.00 / 1) (#23)
by Misagon on Thu Nov 02, 2000 at 02:28:40 PM EST

I used mod_rewrite for a site which needed to authenticate users before allowing them to download files. When the user saves the file on her local harddrive, she should get the real filename and not the name of the script.
Don't Allow Yourself To Be Programmed!
Does anyone use mod_rewrite? | 23 comments (22 topical, 1 editorial, 0 hidden)
Display: Sort:


All trademarks and copyrights on this page are owned by their respective companies. The Rest 2000 - Present Kuro5hin.org Inc.
See our legalese page for copyright policies. Please also read our Privacy Policy.
Kuro5hin.org is powered by Free Software, including Apache, Perl, and Linux, The Scoop Engine that runs this site is freely available, under the terms of the GPL.
Need some help? Email help@kuro5hin.org.
My heart's the long stairs.

Powered by Scoop create account | help/FAQ | mission | links | search | IRC | YOU choose the stories!