Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite headache

mod_rewrite

         

Doktor13

4:41 am on Feb 5, 2006 (gmt 0)

10+ Year Member



Hey Y'all,

I've been beating this one to death and I'm sure we've got an error between the keyboard and the ol chair here. Someone has had to have seen this or something similar before. I could really use some eyeballs this one, so someone could give me a clue. I've got a working virtual host, with an alias directive contained within that I'm attempting to do a little redirection with. Here is a brief list of the test cases I'm using in the browser:

[site.net...]
[site.net...]
[site.net...]
[site.net...]
[site.net...]
[site.net...]
[obviously not real names used here]

Here's the offending piece from the virtual host configs:

Alias /sentry /mnt/lan/service
<Directory "/mnt/lan/service">
Options FollowSymLinks

# mod_rewrite engaged...
RewriteEngine ON
RewriteBase /sentry

# handle requests for the alias default...
RewriteCond %{REQUEST_URI} ^/sentry [NC,OR]
RewriteCond %{REQUEST_URI} ^/sentry/
RewriteRule ^/*$ /mnt/lan/service/master.html [L]

# handle all requests for hosted clients...
RewriteCond %{REQUEST_URI} ^/sentry/([a-z]+) [NC] -d
RewriteRule ^/*$ /mnt/lan/service/%1/%1.html [L]

AllowOverride None
Order allow,deny
Allow from all
</Directory>

The ruleset for the alias default (master.html) works as advertised, the rest is what's kickin' my arse. This is my first pass at using mod_rewrite, and when I got the alias default working I thought this was gonna be rather easy. Yeah, right...

At any rate, this probably shouldn't be that difficult. I've evidently been in front of this terminal for way too long today. My apoligies for the wasted bandwidth if this is an all-to-frequently covered subject, but my tired old eyes have about had it for today...

Thanx in advance for any/all input - it is greatly appreciated...

Peace...

--
The Doktor

"The fact that no one understands you does not make you an Artist!"

jdMorgan

3:32 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove unnecessary duplication:
# handle requests for the alias default...
RewriteCond %{REQUEST_URI} ^/sentr[b]y/?[/b]
RewriteRule ^/*$ /mnt/lan/service/master.html [L]

Directory-exists check should use REQUEST_FILENAME
 # handle all requests for hosted clients...
RewriteCond [b]%{REQUEST_FILENAME}[/b] ^/sentry/([a-z]+) [NC] -d
RewriteRule ^/*$ /mnt/lan/service/%1/%1.html [L]

It is sometimes necessary to use the construct
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} to make this work.

Outstanding questions:

What do you mean by the pattern "^/*$"? The translation of this pattern is "Match any URL-path composed of zero or more slashes (and nothing else)." Is that what you want?

I can't offer much more, since the "working code" was not presented for comparison, and there is no description of specifically *how* the above code fails to function.

Jim

Doktor13

4:13 am on Feb 6, 2006 (gmt 0)

10+ Year Member



Hey Jim,

Thanx so much for your reply. My apologies for not including more detailed information. I've included the whole of the virtual host config. In the spirit of complete-ness, other relevant information is that the virtual host root is served from a Fedora Core 3 boxen, and the /sentry alias is a Windoze SAMBA share, mounted locally on again the Fedora boxen. That's the need for the whole rewrite 'floor show'. Once I get this worked out, I can lock it down tight and be down with it - the security is a PITA in and of itself...

At any rate, the 1st change you replied with was nice, I'm certainly down with slimming down the code. What's even better, is that's it's most likely gonna be that much faster. Now, how that 1st RewriteRule works?!? [*insert levity here*] I pinched that code from a forum somewhere, cause as I'd said in the previous post, this is my maiden voyage on the mod_rewrite high seas. The second change you proposed, well, No Joy there...

So, here's the VirtualHost config file for the server as per your request {with the changes you've suggested/recommended}:

<VirtualHost 172.16.13.100>
ServerName dev.site.net
DocumentRoot /mnt/devnet/www-root/host-sites/site.net-dev
ErrorLog logs/error_log.site-net-dev
CustomLog logs/access_log.site-net-dev common
RewriteLog logs/rewrite_log
RewriteLogLevel 9
DirectoryIndex index.html index.php
<Directory "/mnt/devnet/www-root/host-sites/site.net-dev">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /sentry /mnt/lan/service
<Directory "/mnt/lan/service">
Options FollowSymLinks

# mod_rewrite engaged...
RewriteEngine ON
RewriteBase /sentry

# handle requests for the alias default...
RewriteCond %{REQUEST_URI} ^/sentry/?
RewriteRule ^/*$ /mnt/lan/service/master.html [L]

# handle all requests for hosted clients...
RewriteCond %{REQUEST_FILENAME} ^/sentry/([a-z]+) [NC] -d
RewriteRule ^/*$ /mnt/lan/service/%1/%1.html [L]

AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Some of the things in this initial introduction to it all is just a bit mystifying, at the moment. Once I can see what's actually happening with something that's working (apparently properly) I can make more sense out of things. At that point, I'm quite sure I could handle this sorta thing going forward - gotta crawl before I walk. The debug log helps, but sawing that log is pretty hairy if you don't understand the output codes and the sequence. Perhaps there's a forum for mod_rewrite dorks? *wink - grinning*

Thanx in advance for all your help and insight, it certain does not go unnappreciated!

Peace...

jdMorgan

4:51 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes sorry, I posted in a hurry and that code is no good. It appears to be a combination of two different functions, and it won't work.

It's still not totally clear what you want to do with these rewrites, but the following code is syntactically correct:


# handle requests for the alias default...
RewriteRule ^/sentry/? /mnt/lan/service/master.html [L]
#
Directory-exists check should use REQUEST_FILENAME
# handle all requests for hosted clients...
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/sentry/([a-z]+)$ /mnt/lan/service/$1 [L]

Jim