Forum Moderators: phranque

Message Too Old, No Replies

Request URI syntax

         

Odatpup

2:15 pm on Aug 21, 2005 (gmt 0)

10+ Year Member



Hello all. Trying to get the hang of REQUEST_URI. Would the following in my htaccess file, for example, send custom 403 to any/all requests for files called archives? Spacing OK, etc. Thanks in advance, new.

# Check for requests for archives  
RewriteCond %{REQUEST_URI} /archives/*
# Return 403 for all requests for archives
RewriteRule!^403\.shtml$ - [F]

Also do I need the "L" (last) after the "F"? This would be going in before a list of 'deny by IP', but before a no-hotlinking section. Does that matter?

jdMorgan

2:56 pm on Aug 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code would deny requests for all files in any subdirectory called "/archives/" or "/archives//" or "/archives/////////" and for any file of any type called /archives" in any subdirectory. In both cases, the subdirectory could itself be in any level of subdirectory.

So, this raises several questions:

Do you want to block access to all files in all subdirectories called "/archives/", or just to one particular file called "archive.<something>"?

The rest of the syntax is OK, but look at the RewriteCond pattern and anchoring issues related to the above questions. There is a regular-expressions tutorial cited in our forum charter [webmasterworld.com], and another one in our library [webmasterworld.com].

There is a missing space in the RewriteRule, probably because posting on this forum removes them unless you take steps to prevent it (see page source). Your rule should look like this:


RewriteRule !^403\.shtml$ - [F]

... and no, no [L] is needed; An [L] flag used with [F] or [G] is redundant.

Jim