[thelist] Apache mod_rewrite

William Ross will at spanner.org
Mon Mar 21 10:54:23 CST 2005


On 21 Mar 2005, at 15:00, Rob Smith wrote:

> Hi,
>
> my .htaccess document looks like this:
>
> RewriteEngine On
> RewriteCond %{REQUEST_METHOD} GET
> RewriteRule ^/(.*)$ http://www.mydomain.com/Vendors.php?name=$1 
> [R,L,NS]
>
> But I keep getting either a 404 not found or a 403 forbidden. When it 
> did
> work here's what happened:
>
> http://www.mydomain.com/byhand went to
> http://www.mydomain.com/Vendors.php?name=403.shtml
>
> Huh?

.htaccess files are read a long time after the incoming request is 
translated into a file path. mod_rewrite gets around this by launching 
a new request or subrequest to deal with the revised file path, so it 
isn't a very efficient approach, and it can be hard to debug. If you 
can move the rules higher in the system - into the host configuration, 
for example - life will be much easier.

Meanwhile, the server is looking for 403.shtml, which is presumably the 
error document it serves on a 403 error, which means that at some point 
we are failing a permissions test. I can't say when, because you have 
the R flag set on the rule, which triggers an external redirect: the 
error could be on either the initial or the redirected request. (If 
you're after a silent translation of the address you might want to take 
the R flag off, btw. [L,NS] should suffice.)

But the most likely cause of the 403 is a forbidden DirectoryIndex. 
Have you got a real /byhand/ directory there? Or it could be a 
permissions error on Vendors.php: it's impossible to say without seeing 
the error logs.

best

will




More information about the thelist mailing list