On Mon, Sep 1, 2008 at 1:59 PM, Stephen Wellington <wellingtonsteve@xxxxxxxxx> wrote: > On Mon, Sep 1, 2008 at 1:25 PM, Eric Covener <covener@xxxxxxxxx> wrote: >> On Mon, Sep 1, 2008 at 8:01 AM, Stephen Wellington >> <wellingtonsteve@xxxxxxxxx> wrote: >>> Hi, >>> >>> Am having trouble with mod_rewrite and would appreciate a little help. >>> I've tried searching Google and reading the manual but found little >>> that helps! >>> >>> I am trying to achieve something like this: >>> >>> RewriteRule ^a.php$ b.php [L] >>> RewriteRule ^b.php$ - [F] >>> >>> The intention is that requests to a.php will serve the contents of >>> b.php, but if a user tries to go directly to b.php they are given a >>> 403 error. My understanding is that L flag stops further matching of >>> rules. but this doesn't appear to work, neither does a 'solution' from >>> Google of using the NS flag in the second rule. >> >> Your strings don't start with a slash, which means you're in >> directory/location/htaccess context. >> >> In this context, after any rewrite occurs the entire process is >> re-started with the new URL. This makes 'L' work a little different >> then in virtualhost context. >> >> "Remember, however, that if the RewriteRule generates an internal >> redirect (which frequently occurs when rewriting in a per-directory >> context), this will reinject the request and will cause processing to >> be repeated starting from the first RewriteRule." >> >> Maybe you could set an environment variables [E=foo:bar] to remember >> you've rewritten this request? >> >> -- >> Eric Covener >> covener@xxxxxxxxx >> > > Thank you for your help; I have taken your advice on the environment > variables and used this: > > RewriteRule ^a.php$ b.php [E=foo:bar] > RewriteCond %{ENV:foo} !="bar" > RewriteRule ^b.php$ - [F] > > However requests to a.php are still returning a 403. Could you tell me > if I'm missing the point with the way these variables work? > > Thank you > Resorted to moving the rules inside the <VirtualHost> container in the end. Obviously not quite what I wanted as it means I now have to do a 'apache2ctl restart' whenever I change the config, but I guess that's not the end of the world.. Setting the environment variable - the variable didn't seem to survive (if that makes sense) after that first rule. For instance this: RewriteRule ^.*$ - [E=foo1:bar1] RewriteRule ^a.php$ b.php [E=foo2:bar2] RewriteRule ^b.php$ %{ENV:foo1}%{ENV:foo2}.php [R] would redirect to bar1.php. So clearly the value of foo2 is being forgotten somehow. Thanks anyway Steve --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx