Welcome to WebmasterWorld Guest from 54.211.136.250

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteCond help needed

Webmaster needing help with a RewriteCond

   
4:46 pm on Jun 29, 2003 (gmt 0)

10+ Year Member



Hi all, I am having trouble with a RewriteCond rule im trying to write. So far I have the following in httpd.conf:

RewriteEngine on
RewriteCond %{PATH_INFO} ^/zzz/messages$
RewriteRule!^/zzz/messages/35 /zzz/messages/35/35.html [L,R]

What I am trying to do is when a user tries to access the "/zzz/messages" folder and tries to access any sub folder other than "35" they are redirected to "/zzz/messages/35/35.html"

Ewan

5:25 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



I have still being trying to get this to work. I enabled logging and got:
"RewriteCond: input='/zzz/messages/112/112.html' pattern='^/zzz/messages/$' => not-matched"

My RewriteCond is now "RewriteCond %{REQUEST_URI} ^/zzz/messages/$"

Any help?
Ewan

5:48 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



ewanfischer,

Form the looks of it, the problem is that you have end-anchored the pattern in the RewriteCond, and that the logic of "this directory and NOT this subdirectory" is reversed as implemented.

> What I am trying to do is when a user tries to access the "/zzz/messages" folder and tries to access any sub folder other than "35" they are redirected to "/zzz/messages/35/35.html


RewriteCond %{REQUEST_URI} !^/zzz/messages/35
RewriteRule ^/zzz/messages/ http://www.yourdomain.com/zzz/messages/35/35.html [R,L]

Note that this is written for use in http.conf. For use or testing in .htaccess, remove the leading slash of the RewriteRule pattern.

I'm not sure this code captures exactly what you're trying to do. Because this code implements an external redirect, it will redirect both users and internal subrequests, making only /zzz/messages/35 accessible for requests to anything in the /zzz/messages/ path. If you are just trying to establish a fixed "entry point" to your messages, you will have to add Conds which look at the HTTP_REFERER and other vars in order to allow access to other subdirs after the user enters through the proper page. Actually, without session tracking, it won't work perfectly, but you might get close enough.

HTH,
Jim

6:10 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



Yep thats exactly what I was trying to do :)

Thanks Jim it worked perfectly!