mod_rewrite and if cases?

New to mod_rewrite? This is a good place to start.

mod_rewrite and if cases?

Postby Guest » Fri Apr 16, 2004 3:50 am

Hello everbody!

First of all: I'm a German Kraut, so please have mercy with me and my english skills. :-)

This is my very first posting in this BBS and I hope I can get some inspiring answers here.

The problem: I wrote a CMS (in Perl) that simply merges a template with a contentfile and writes it to the filesystem in a cache dir. But that should only be done, if the file does not allready exist in the cache. My "brilliant" idea was to write a mod_rewrite ruleset.

After spending plenty of time with reading, reading and reading (RTFM), I found myself a solution that almost works. - But only almost.

Here it goes:
UNrewritten URL to a typical cachefile: http://mydomain.xy/-/Cache/myfile.htm
REwritten URL to a typical cachefile: http://mydomain.xy/Cache/myfile.htm - This URL will be linked and published for browsing.

Right URL to a file thats not stored in the Cache: http://mydomain.xy/-/index.pl?PID=myfile - All files don't have any extension!

My big problem is, that RULE1 and RULE2 work perfectly for themselfs but not together. When I erease RULE2, RULE1 works (and the other way arround). But both together don't do their job right. I tried to program something like a IF/ELSE Case, wich didn't worked. I was thinking about something like:

Code: Select all
if (file exist) { provide cachefile }
else { call CMS }



Abstract from my .htaccess
Code: Select all
RewriteEngine on
RewriteBase /-/

# RULE 1: take the cachefile, if exist.
#
RewriteCond %{REQUEST_URI} (.*)\.htm$
RewriteRule (.*)\.htm$ /-/Cache/$1 [L]
#

# RULE 2: call the CMS, if the file does not exist.
#
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)\.htm$ /-/?PID=$1 [T=application/x-httpd-cgi,L]
#


Of course I could do all this in Perl. But I guess it wouldn't be that perfomant than doing it with mod_rewrite. And would still have the SEO problem.
Guest
 

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 28 guests

cron